4

I have been stuck on this error (for importing tensorflow) for a while, I looked on various different pages and didn't find a solution that helped. I tried installing vs 2015 as said on the internet, but that didn't work. I have downloaded python 3.8.0 rather than 3.8.2, but i still get the error. Please Help! windows 10, latest version of tensorflow

    >>> import tensorflow
Traceback (most recent call last):
  File "C:\...\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\...\Python\Python38\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\...\Programs\Python\Python38\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
    from tensorflow.python.eager import context
  File "C:\...\Programs\Python\Python38\lib\site-packages\tensorflow\python\eager\context.py", line 35, in <module>
    from tensorflow.python import pywrap_tfe
  File "C:\...\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\...\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\...\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
    from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.

Failed to load the native TensorFlow runtime.


See https://www.tensorflow.org/install/errors

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

Omar Zayed
  • 91
  • 1
  • 10

2 Answers2

3

I found a solution to my question: Using pip: There are system requirements that I won't bother talking about all of them as they could be found on the tensorflow website, though the 3 problems I had were that:

  1. I didn't install Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019.
  2. Long paths weren't enabled

So just following a youtube tutorial didn't finish the problem. I had to download it based on the way on tensorflow's website.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Omar Zayed
  • 91
  • 1
  • 10
1

Create a virtual environment in python. For the creation of a virtual environment, you need virtualenv library.

pip install virtualenv

After installing create your virtual environment.
command - virtualenv "NAME-OF-ENVIRONMENT"

eg

virtualenv myenv

This will create a directory called myenv. To activate the virtual environment you have go inside the myenv/scripts folder, open a cmd prompt and type activate.

eg

cd myenv/Scripts
activate

Get out of the Scripts folder

cd ../..

Now install TensorFlow.

pip install tensorflow

Note: Always create a virtual environment when working in any project and keep your python package clean. You can delete these environments if they become corrupt or stop working correctly due to any reason, without and fear.

Aniket Bote
  • 3,456
  • 3
  • 15
  • 33