I have installed Python3 and TensorFlow 1.0 on my Mac and it works fine when I run code in "terminal" with command line.
$ python3 /Users/yeongsanggim/git/pythonstudy/study/tf01.py
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.8.0.dylib locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.5.dylib locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.8.0.dylib locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.1.dylib locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.8.0.dylib locally
But when I use IntelliJ or PyCharm and run the same code,
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /Users/yeongsanggim/git/pythonstudy/study/tf01.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/__init__.py", line 61, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: #rpath/libcudart.8.0.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/_pywrap_tensorflow.so
Reason: image not found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/yeongsanggim/git/pythonstudy/study/tf01.py", line 1, in <module>
import tensorflow as tf
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/__init__.py", line 72, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/__init__.py", line 61, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: #rpath/libcudart.8.0.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/tensorflow/python/_pywrap_tensorflow.so
Reason: image not found
Failed to load the native TensorFlow runtime.
See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error
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
Why is this happening???
How can I fix this?
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib
Choose "Edit Configuration". You will see an Environment option where you need to click on the ... box and enter the DYLD_LIBRARY_PATH that applies to your case.
Note that there's an Environment option for the specific file you're working on (it will be highlighted in the left panel) and for Defaults (put DYLD_... there as well if you want future files you create to have this). Note that you need to save this config or else when you close PyCharm it won't stick.
Related
An error occurs when importing tensorflow.
My environment
Ubuntu 18.04 Desktop
Nvidia graphic driver 470.42.01
CUDA 11.4
Python 3.6.14 (Anaconda)
TensorFlow-gpu 1.12.0
CUDA environment variable setup completed (11.4)
Linked symbolic link at /usr/local/CUDA from /usr/local/CUDA-11.4
(The reason for using the old version is that the SDK of the project was written in the past.)
When importing tensorflow after running Python, the following error occurs:
>>> import tensorflow
Traceback (most recent call last):
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/(username)/anaconda3/envs/mdk/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/(username)/anaconda3/envs/mdk/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.9.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 "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/(username)/anaconda3/envs/mdk/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/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/(username)/anaconda3/envs/mdk/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/(username)/anaconda3/envs/mdk/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/home/(username)/anaconda3/envs/mdk/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: libcublas.so.9.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.
I installed CUDA 9.0 to fix this error.
However, the same error came out with version 7.0.
Do I need to install all the versions of CUDA that I need?
Or is there any other way to solve this?
According to Tensorflow documentation, TF v1.12 requires CUDA 9.0.
Take a look at screenshot for information,
Once Appropriate CUDA version installed, Add the CUDA®, CUPTI, and cuDNN installation directories to the %PATH% environmental variable.
Follow the installation steps mentioned here and change CUDA versions as per the requirement i.e CUDA 9.0.
I have the Centos7 minimal installation with the GNOME desktop installed on as well. I mainly use the terminal remotely but I use the GUI when working with the camera.
Here are the programs/packages that I use:
Python 3.4.9
Tensorflow-gpu 1.13.1
Cuda 10.0
Nvidia Drivers 481.56
When I am using the terminal and import tensorflow, everything runs as it should.
When I start up the GUI and try to import tensorflow on the GUIs terminal, I get the typical import error:
>>>import tensorflow as tf
Traceback (most recent call last):
File "/usr/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/lib/python3.4/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 "/usr/lib64/python3.4/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
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 "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/usr/lib/python3.4/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/lib/python3.4/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/lib/python3.4/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 "/usr/lib64/python3.4/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
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.
Again, I do not get this error when I run it on the terminal WITHOUT the GUI. Even when I bring up the GUI and get this import error, I'll SSH into my machine and I'll still be able to import tensorflow on the SSH window.
My paths should be fine because, again, it successfully imports, just not when importing it on the GUI. This is a really weird issue and I am completely lost as to why this is happening.
I have also tried various, compatible, versions of tensorflow and Cuda and other Desktops. I still get this issue.
I want to add that I recently reinstalled everything and just copied over my /home directory into the new installation. So before this, everything worked fine with or without the GUI.
This is strange. The error says that it could not find path to CUDA10 file (libcublas.so.10.0). However it is not complaining if you import TF on the SSH window. Is there any Firewalls or any restrictions acting when you open with GUI? Thanks!
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.
When I import tensorflow it gives me this error:
Traceback (most recent call last):
File "C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\User\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\User\Anaconda3\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\User\Anaconda3\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "", line 1, in
import tensorflow as tf File "C:\Users\User\Anaconda3\lib\site-packages\tensorflow__init__.py",
line 24, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File
"C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python__init__.py",
line 49, in
from tensorflow.python import pywrap_tensorflow File "C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 74, in
raise ImportError(msg) ImportError: Traceback (most recent call last): File
"C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 58, in
from tensorflow.python.pywrap_tensorflow_internal import * File "C:\Users\User\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in
_pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\User\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\User\Anaconda3\lib\imp.py",
line 243, in load_module
return load_dynamic(name, filename, file) File "C:\Users\User\Anaconda3\lib\imp.py", line 343, in load_dynamic
return _load(spec) ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
Please Help me with this
The following might me the problems :
You have not installed Microsoft C++ Redist 2015 Update 3. It contains the missing dll. You need to download the 2015 update 3 version only.
Your CPU doesn't support AVX instructions which are needed by TensorFlow. You will need a processer which supports AVX.
I just solved this same issue with my system (Win 10, 64 bit). Following are the details of how I resolved this issue:
Install VS 2017, tensorflow doesn't use it but having it helps in the smooth installation of CUDA toolkit.
Update NVDIA driver from windows device manager.
Download and Install CUDA toolkit (version 10.1).
Download and unzip CUDnn 7.6.5. Copy the extracted files into a folder in C drive.
Add ~\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin, ~\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin and cudnn-10.1-windows10-x64-v7.6.4.38\cuda\bin to PATH
Doing import tensorflow as tf after the above steps solved the issue.
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.