DLL error when importing tensorflow in anaconda environment - python

I have installed tensorflow in the anaconda environment. I have installed the latest anaconda and tensorflow by "conda install tensorflow-gpu". When I try to import tensorflow it works in the jupyter notebook. But the same code does run when I try to run from python terminal or when I run by "start debugging" from vs code. This is the error I am getting:
Traceback (most recent call last):
File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\lib\python\ptvsd\__main__.py", line 410, in main
run()
File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\lib\python\ptvsd\__main__.py", line 291, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "d:\Projects\SASRec\SASRec Pytorch\main.py", line 7, in <module>
import tensorflow as tf
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\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\Admin\Anaconda3\envs\tf-gpu\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
Can anyone kindly give me a solution and make my life easier. Thanks!

You probably already had some version of python installed (e.g. 3.6.6) before installing Anaconda with Python 3.7 and prepared it to use TensorFlow.
Because Anaconda comes with its own instance of Python you have installed the TensorFlow dependencies into the Anaconda instance of Python.
When you use the console, you most likely use your non-Anaconda-Python instance, which does not have TensorFlow with all its dependencies installed.
You can either install the missing dependencies for your non-Anaconda-Python or start the script with the Anaconda version of Python. You can do the later by calling python using the full path like /path/to/anaconda/bin/python yourscriptusingtensorflow.py or prepending the anaconda binary path to your console's $PATH variable.

So, after a lot of installing, uninstalling and reinstalling and scraping various similar issues in github and stackoverflow, I got a pretty simple solution. In my system, I only have Anaconda installed and c++ build tools from Microsoft (2019), and nothing else. Then I installed tensorflow as follows:
conda install tensorflow-gpu=1.10
Apparently, this older version is compatible with the DLL and everything seems to work.

Related

ImportError: DLL load failed while importing strings: The specified module could not be found

I am trying to load a language model in spaCy, but I get errors when I try to install the model, both in the legacy command and the newer command.
Installing via the legacy shortname:
python -m spacy download en
Traceback (most recent call last):
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 188, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 147, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\site-packages\spacy\__init__.py", line 13, in <module>
from . import pipeline # noqa: F401
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\site-packages\spacy\pipeline\__init__.py", line 1, in <module>
from .attributeruler import AttributeRuler
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\site-packages\spacy\pipeline\attributeruler.py", line 6, in <module>
from .pipe import Pipe
File "spacy\pipeline\pipe.pyx", line 1, in init spacy.pipeline.pipe
ImportError: DLL load failed while importing strings: The specified module could not be found.
Installing using the newer full name:
python -m spacy download en_core_web_sm
Traceback (most recent call last):
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 188, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 147, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\site-packages\spacy\__init__.py", line 13, in <module>
from . import pipeline # noqa: F401
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\site-packages\spacy\pipeline\__init__.py", line 1, in <module>
from .attributeruler import AttributeRuler
File "C:\Users\mikkelson\AppData\Local\Programs\Python\Python39\lib\site-packages\spacy\pipeline\attributeruler.py", line 6, in <module>
from .pipe import Pipe
File "spacy\pipeline\pipe.pyx", line 1, in init spacy.pipeline.pipe
ImportError: DLL load failed while importing strings: The specified module could not be found.
Python 3.9 is installed via anaconda, spaCy v 3.0.6 is installed via pip, and I'm in Windows environment. How can I fix this?
Been facing the same issue, was told problem comes from python3.9 so i tested with 3.8 and this didn't help however installing the following Visual C++ Redistributable solved my problem https://www.microsoft.com/en-in/download/details.aspx?id=48145
I hope that helps!
The issue is not related to particular way you attempt to download models but rather to an issue with loading DLL (pipe.pyx) which is very likely to have a dependency on VS Build Tools that you are missing (see details here).
Once you install this dependency, it should start working.

What causes Tensorflow Import Error: DLL load failed?

I am using Anaconda environment on Windows 10. I have installed tensorflow-gpu using pip and when I try to import tensorflow, I get this import error below. I have tried to use cpu version of tensorflow and to reinstall all packages with new conda environment. My python is version 3.7 and tensorflow-gpu version 2.1.0.
>>> import tensorflow as tf
Traceback (most recent call last):
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\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\ossik\anaconda3\envs\tensorflow-gpu\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: Määritettyä osaa ei löydy.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
from tensorflow_core import *
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\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\ossik\anaconda3\envs\tensorflow-gpu\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\ossik\anaconda3\envs\tensorflow-gpu\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: Määritettyä osaa ei löydy.
Failed to load the native TensorFlow runtime.
Do you have any idea what causes this error?
Try to downgrade and install tensorflow.
pip install tensorflow==2.0
if you use gpu
pip install --upgrade tensorflow-gpu==2.0
or try downloading these visual studio files
click here
This could be because you have a CPU(probably old), which can not support AVX instructions (for example, Intel Pentium or similar). You could solve this problem using this approach:
pip3 uninstall tensorflow
Go here: link with tensorflow 2.1.0 wheels which has been precompiled with SSE2 instructions.
Download wheel to your project, then install tensorflow using pip install <filename.wheel>.
And try again - error should be solved

Tensorflow ImportError: DLL load failed: The specified module could not be found

I've seen that a lot of questions have already asked this, but it seems to be very specific as none of the answers seem to work.
Let me explain the steps that I have taken to install everything:
I started with installing Python 3.7.4 and installed tensorflow after that. The command I ran is: pip install -q tensorflow=2.0.0-alpha0. This didn't seem to work and I soon figured out that this is because of the version of Python. Tensorflow doesn't support 3.7 yet, so I installed Python 3.6.0.
I then installed tensorflow again with the following command: pip3.6 install tensorflow. Note the explicit pip3.6. I then select python 3.6 in the configuration of Visual Code's Python Debugger. I ran the following code (single line) and gave me the following error:
Python
import tensorflow as tf
Output
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\Python36\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
from tensorflow_core import *
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Program Files\Python36\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Program Files\Python36\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\Program Files\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Program Files\Python36\lib\site-packages\tensorflow_core\core\framework\graph_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
File "C:\Program Files\Python36\lib\site-packages\google\protobuf\descriptor.py", line 47, in <module>
from google.protobuf.pyext import _message
ImportError: DLL load failed: The specified module could not be found.
After some searching, someone said that uninstalling tensorflow-estimator and tensorflow-gpu may work, because of unsupported gpu's. Even though I doubted this since I have an RTX 2080, I decided to give it a go, but I still got the same result.
I'm hoping any of you would be able to help me with this.
Thanks in advance!
UPDATE
After installing Anaconda and using conda to install my packages with (instead of pip) this issue has been resolved. However, a nice issue occurs. With the someline of code I get the following error (pretty much the same as the last one, but a different package module):
Traceback (most recent call last):
File "c:\Users\Meine Zeinstra\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Users\Meine Zeinstra\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 432, in main
run()
File "c:\Users\Meine Zeinstra\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 316, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\Meine Zeinstra\Documents\Projects\Python_Neural_Networks\Tutorial_1\Tutorial_1.py", line 1, in <module>
import tensorflow as tf
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\site-packages\tensorflow\__init__.py", line 34, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\site-packages\tensorflow\python\__init__.py", line 47, in <module>
import numpy as np
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Users\Meine Zeinstra\.conda\envs\Python 3.6\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
I hope you can help me with this new issue.

Can't import TF using PyCharm and venv

I read this, this and this. These are not my case. Also I tried to solve my problem using this.
Problem description
I installed cuda 10.0, pip 19.0.2, python 3.6.7, ipython 7.2.0, tensorflow-gpu 1.13.0-rc1, PyCharm CE 2018.3.4. All python modules are installed in virtual environment.
I chose venv interpreter as the Project Interpreter and the Python Console Interpreter in PyCharm.
When I try to import tensorflow
import tensorflow as tf
I've succeed using terminal ipython and failed using PyCharm.
/home/roman/dev/venv/bin/python /home/roman/dev/box.neuro/test.py
Traceback (most recent call last):
File "/home/roman/dev/venv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/roman/dev/venv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/roman/dev/venv/lib/python3.6/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 "/home/roman/dev/venv/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/home/roman/dev/venv/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.10.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 "/home/roman/dev/box.neuro/test.py", line 1, in <module>
import tensorflow as tf
File "/home/roman/dev/venv/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/roman/dev/venv/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/roman/dev/venv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/roman/dev/venv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/roman/dev/venv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/roman/dev/venv/lib/python3.6/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 "/home/roman/dev/venv/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/home/roman/dev/venv/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
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.
Process finished with exit code 1
Additional info
I verified that I use the same ipython in the following way. I checked import requests, noticed that it is not imported in terminal and PyCharm, installed it in terminal and verified that I can import it in both now.
I checked the following:
import os
print(os.environ['PATH'])
Noticed difference in terminal and PyCharm. Then I added environment variable PATH in Settings->Build, Execution, Deployment->Console->Python Console. Now output is the same, but I still can't import tensorflow in PyCharm.
I checked the following:
import os
print(os.environ['LD_LIBRARY_PATH'])
Noticed difference in terminal and PyCharm. PyCharm IPython output is empty and terminal IPython output is the following:
'/usr/local/cuda-10.0/lib64'
I found workaround myself. I added environment variable 'LD_LIBRARY_PATH' in Settings->Build, Execution, Deployment->Console->Python Console. To use Run/Debug configurations I added the same environment variable for them. It is not user-friendly because I should do it for every configuration again and again.
All previous times I installed PyCharm on different computers it worked properly with TF or better to say cuda libraries.
Also, I found issue on PyCharm tracker. So, if you are interested in fix, feel free to vote for it.

Unable to use tensorflow

I installed tensorflow on my mac via pip and I'm using anaconda as my IDE.
when I run the command
import tensoflow
I'm getting the following error:
Traceback (most recent call last):
File "<ipython-input-3-a649b509054f>", line 1, in <module>
import tensorflow
File "/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/Applications/anaconda3/lib/python3.5/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 "/Applications/anaconda3/lib/python3.5/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/Applications/anaconda3/lib/python3.5/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: dlopen(/Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 10): Library not loaded: #rpath/libcublas.8.0.dylib
Referenced from: /Applications/anaconda3/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so
Reason: image not 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 also ran pip list in my terminal to check if it was installed properly.
It lists all the tensorflow libraries that I have installed.
I'm using Anaconda v1.6.8 and Spyder v3.2.3
I can see that you have 2 versions of tensorflow. with (1.1.0) and without (1.3.0) gpu support. But error you are getting is because the gpu libraries are not properly installed.
For tensorflow-gpu==1.1.0 follow these instructions.
Unfortunatelly tensorflow dropped support for gpu on Mac since v1.2, but this answer may help you setup for a higher version.

Categories