Unable to import tensor flow into my python code - tensorflow

I am trying to import the tensorflow model into my code but its always thowing me the dll Link error, i have tried installing various versions but none seem to work.
i have installed multiple versions of tensorflow
uninstalled and reinstalled anaconda
tried installing tensorflow using wheelfiles
ImportError: Traceback (most recent call last): File
"C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 58, in
from tensorflow.python.pywrap_tensorflow_internal import * File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in
_pywrap_tensorflow_internal = swig_import_helper() File "C:\ProgramData\Anaconda3\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:\ProgramData\Anaconda3\lib\imp.py",
line 243, in load_module
return load_dynamic(name, filename, file) File "C:\ProgramData\Anaconda3\lib\imp.py", line 343, in load_dynamic
return _load(spec) ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
I expect the tensorflow to be successfully install and run on my machine
Note : i use windows 10 OS

I think the problem may be due to protobuf, try downgrading protobuf to 3.6.0 using:
pip install protobuf==3.6.0
If not try installing tensorflow using wheel file provided in the below link:
https://github.com/fo40225/tensorflow-windows-wheel/tree/master/1.12.0/py36/CPU/sse2
Hope this could solve your issue.

Related

I installed tensorflow package but it is showing the following error, so what should i do?

problem in tensorflow - ImportError: Traceback (most recent call last):
File "C:\Users\SUBHAM KUMAR\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\SUBHAM KUMAR\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\SUBHAM KUMAR\AppData\Local\Programs\Python\Python38\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\SUBHAM KUMAR\AppData\Local\Programs\Python\Python38\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\SUBHAM KUMAR\AppData\Local\Programs\Python\Python38\lib\imp.py", line 342, in load_dynamic
return _load(spec)
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.
You need to have a 64 bit Python if you are using 32 bit. On Windows you need to have Microsoft Visual C++ 2015-2019 Redistributable (x64). If your issue is not resolved other possible reasons are mentioned here.
Note: Python binary is installed from official sources not from Windows marketplace.
Workaround for the above issue, you can create virtual environment on anaconda and install tensorflow as shown below
# Create virtual environment
conda create --name TF_VE
# When conda asks you to proceed, type y:
proceed ([y]/n)?
# Activate virtual environment
conda activate TF_VE
# Install the TF Version
conda install tensorflow

I installed tensorflow 2.0 but jupyter doesn't see it?

I seem to have a problem with installing tensorflow 2.0. After many attempts finally command "conda list" shows tensorflow 2.0 package successfully installed but when I try to import it in jupyter I get the error:
ImportError: Traceback (most recent call last):
File "C:\Users\giuse\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58,
in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\giuse\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\giuse\anaconda3\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\giuse\anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\giuse\anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
Can anybody help please?
If you have still below error:
ImportError: DLL load failed: The specified module could not be found.
Try to install the proper version of:
visual c++ redistributable for visual studio 2019
Or try virtual environment:
Creation of the environment
conda create -n test_env python=3.x anaconda
Activation
conda activate test_env
Deactivation
conda deactivate
Getting rid of it
conda remove -n test_env --all

Keras the specified module could not be found

I am getting this error on Keras.
ImportError: DLL load failed: The specified module could not be found while importing Keras
What I tried?
-initially "conda install -c conda-forge keras"
-then i also followed the tensorflow install instructions on tensorflow website
-I tried installing Microsoft Visual C++ that did not solve
-Also downloaded a msvcp140_1.dll file and pasted it in the sys32 and syswow64 of windows folder,did not help
-while importing the tensorflow it is reflecting the same problem
-OS-MSW-8.1
import keras
Error in callback <bound method AutoreloadMagics.post_execute_hook of <autoreload.AutoreloadMagics object at 0x0000006394266548>> (for post_execute):
Traceback (most recent call last):
File "C:\Users\admin\Anaconda3\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\admin\Anaconda3\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\admin\Anaconda3\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\admin\Anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\admin\Anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
As confirmed in comments, the OP was missing some of the Visual Studio redistributables. After installing appropriate (in terms of architecture) vc_redist from here everything worked fine.

Tensorflow-alpha-gpu issue ImportError: DLL load failed: The specified module could not be found

I previously had cuda9.0_0 and cudnn7.1.4, I wanted to run tf-alpha in gpu,from this tf guide:https://www.tensorflow.org/install/gpu I found I need cuDNN SDK (>= 7.4.1) and cuda10.so I uninstalled previous versions from control panel and installed Cuda compilation tools, release 10.1, V10.1.105.So, I should have imported tf succesfully,but not,I got the error.
And if I had
conda list cudnn
I got
# packages in environment at F:\Anaconda:
#
# Name Version Build Channel
cudnn 7.1.4 cuda9.0_0 anaconda
Though I installed cuda 10 and cudnn succesfully verified by running
nvcc --version
I have anaconda installed and had previous cuda and I used tf 1.12.0 gpu ago and my gpu is nvidia 1050ti
import tensorflow as tf
I expected it to import tensorflow 2.0 alpha gpu version
The error I got:
Traceback (most recent call last):
File "F:\Anaconda\lib\site-packages\tensorflow\python
\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "F:\Anaconda\lib\site-packages\tensorflow\python
\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "F:\Anaconda\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 "F:\Anaconda\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "F:\Anaconda\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 "F:\Anaconda\lib\site-packages\tensorflow\__init__.py", line 27, in
<module>
from tensorflow._api.v2 import audio
File "F:\Anaconda\lib\site-packages\tensorflow\_api\v2\audio
\__init__.py", line 8, in <module>
from tensorflow.python.ops.gen_audio_ops import decode_wav
File "F:\Anaconda\lib\site-packages\tensorflow\python\__init__.py", line
49, in <module>
from tensorflow.python import pywrap_tensorflow
File "F:\Anaconda\lib\site-packages\tensorflow\python
\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "F:\Anaconda\lib\site-packages\tensorflow\python
\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "F:\Anaconda\lib\site-packages\tensorflow\python
\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "F:\Anaconda\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 "F:\Anaconda\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "F:\Anaconda\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/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
my python version is 3.6.6
Note:
TensorFlow Version >= 1.13 requires CUDA 10.0 and TensorFlow Version < 1.13 (till TF 1.5) requires CUDA 9.0.
See Software requirements to know more https://www.tensorflow.org/install/gpu#software_requirements
Also requires NVIDIA® GPU card with CUDA® Compute Capability 3.5 or higher.
See Hardware requirements to know more
https://www.tensorflow.org/install/gpu#hardware_requirements
Hope this helps.

Tensorflow: ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory

I'm having problems in importing tensorflow in python3:
>>> import tensorflow as tf
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/usr/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "/usr/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory
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 am using Nvidia drivers version 381.09 beta, as version 375 has this bug: https://askubuntu.com/questions/896221/strange-artifacts-along-window-borders-after-waking-computer-from-sleep-mode?noredirect=1&lq=1
I have install CUDA 8.0 and cuDNN-v6.0:
rharish#rharish-GL552VW:~$ cd /usr/local
rharish#rharish-GL552VW:/usr/local$ ls
bin cuda etc include man share
computecpp cuda-8.0 games lib sbin src
Also, libcusolver.so.8.0 exists in /usr/local/cuda/lib64/:
libcusolver.so.8.0 in 'ls' output
I have uninstalled and reinstalled CUDA, cuDNN, and built tensorflow from sources. This problem has been occuring since updating the Nvidia drivers to version 381.09 beta. Any help?
Found the solution:
I reinstalled nvidia-381, CUDA-8.0 (using the runfile) and cuDNN 6.0. Then I added the following in my .bashrc:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/
No need for reinstallation. Install nvidia-cuda-dev:
sudo apt install nvidia-cuda-dev
Install cuDNN (which you download from https://developer.nvidia.com/cudnn), and set LD_LIBRARY_PATH accordingly (to cuda/lib64).
You could be having this problem if you installed the latest version of CUDA (9.0). If this is the case, you'll have the libcusolver.so.9.0 file or directory on your computer, but not 8.0, so python can't find it to import. Tensorflow doesn't yet support CUDA 9.0 (as of Oct 18th 2017).
To fix this, install CUDA 8.0, which can be found here. You can find all their legacy releases at the bottom of the main download page.
I faced this error due to incompatibility between Tensorflow version with CUDA.
I had tensorflow_gpu-1.3.0, CUDA 9 and cuDNN 7 which are incompatible as per this https://www.tensorflow.org/install/source#tested_build_configurations
so I uninstalled tensorflow_gpu-1.3.0 and installed tensorflow_gpu-1.5.0 and it worked fine
In addition to having the paths correctly set, the version of Tensorflow you have installed must be compatible with the CUDA driver version you have in your system otherwise it won't work.
See the link