import tensorflow as tf gives errors even after installing without errors

471 Views Asked by At

I've been trying to solve this issue for long time. After many attempts in my existing python=3.5 env (in Anaconda), I deleted it and created a new env again just to properly install tensorflow with gpu support. To do that I did conda create -n FALL python=3.5 and then pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.11.0-cp35-cp35m-win_amd64.whl as suggested in tensorflow site, because I am on Windows 10 and have Anaconda. There was no error during installation. And I have been using Cuda 8.0 and cuDNN for my other deep learning practices without any hinders. So I could type python in my activated env. To check if tensorflow is installed accurately I did import tensorflow as tf and got

Traceback (most recent call last):
  File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:\Users\username\Anaconda3\envs\FALL\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\username\Anaconda3\envs\FALL\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 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:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\username\Anaconda3\envs\FALL\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:\Users\username\Anaconda3\envs\FALL\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\username\Anaconda3\envs\FALL\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

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

I would like someone could help me as possible.

1

There are 1 best solutions below

0
On

Not sure if you are still looking for this question to be answered, but seeing as I just battled this very issue for the past few days, I figured I'd leave my two cents here in case it helps anyone moving forward.

As an initial note, I was not installing tensorflow through anaconda, but rather just via a pip install in a python virtualenv. I expect the solution to this issue would be similar using either anaconda or just pip.

It really just turned out in the end that I had one or more programs installed in incompatible versions for tensorflow.

As of my writing of this, tensorflow-gpu requires CUDA 9.0, CUPTI (should be included with the CUDA install), and cuDNN version greater than 7.2 (but note that this version should be compatible with your specific install of CUDA). My problem was that I was unwittingly using CUDA 10.0, which I think is theoretically compatible with tensorflow-gpu (based on cursory searches, it seems to work for some people), but didn't work for me at all.

Long story short, here is exactly the setup/process that worked for me:

  1. CUDA compatible GPU (https://developer.nvidia.com/cuda-gpus to check yours specifically

  2. python 3.5.4

  3. tensorflow-gpu version 1.12.0

  4. CUDA 9.0

  5. CUPTI (again, this is included with your CUDA 9.0 install)
  6. cuDNN 9.0 version 7.4.1.5. To install this correctly, make sure the .dll in /bin gets copied into the /bin folder of Cuda 9, the .h file from /include gets copied into the Cuda 9 /include folder, and the .lib file from /lib/x64 folder gets copied into the /lib/x64 folder for Cuda 9 (this all seems self evident, but oddly some installation guides I've seen only reference copying the .dll over).
  7. visual c++ 2017
  8. Microsoft Visual C++ 2015 Redistributable Update 3 (this can be found under 'Redistributables and Build Tools' here: https://visualstudio.microsoft.com/vs/older-downloads/). Do note that to install this I had to go into programs and settings and manually uninstall the visual c++ 2017 redistributable that was installed when I installed visual c++ to begin with.
  9. Include both CUDA 9 and CUPTI in your path (CUDA (and cuDNN) for me was in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin, and CUPTI was in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\extras\CUPTI\libx64)

After all this importing tensorflow worked fine for me.

I honestly hope this helps someone out there, as this process was incredibly arduous for me personally and I'd love to be able to lessen that for someone else.