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.
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.
So I created a program to load a dataset from TensorFlow and I got an error that I have no idea what it means.
My code is:
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
data = keras.dataset_fashion_mnist
(train_images, train_labels), (test_images, test_labels) = data.data_load()
print(train_labels[1])
I supposed to get a number as output and not an error.
The error is:
Traceback (most recent call last):
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\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\Khosr\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, 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 "helloworld.py", line 1, in <module>
import tensorflow as tf
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
from tensorflow_core import *
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\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\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\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\Khosr\AppData\Local\Programs\Python\Python37\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Khosr\AppData\Local\Programs\Python\Python37\lib\imp.py", line 342, 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
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
I have no idea what to do to solve this and what to try. I made sure that I have tensorflow installed and I do.
I think it has something to do with the library itseff.
Your error seems similar to this: https://github.com/tensorflow/tensorflow/issues/22794
The general solution there is to use a specific version of CUDA with a specific version of tensorflow, e.g.
tensorflow-gpu==1.14.0
python 3.6.8
CUDA v10.0
cudnn 7.4.1.5
Can you provide your library version? I'd recommend using conda to install tensorflow on Windows as it helps a lot with installing the right versions instead of setting things up yourself.
Edit
Please try these steps (Taken from Tensorflow's document: https://www.tensorflow.org/install/pip)
Go to the Visual Studio downloads: https://visualstudio.microsoft.com/vs/older-downloads/
Select Redistributables and Build Tools
Download and install the Microsoft Visual C++ 2015 Redistributable
Update 3
Enable long paths on windows: https://superuser.com/questions/1119883/windows-10-enable-ntfs-long-paths-policy-option-missing
Finally, please make sure your CPU supports AVX instructions: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#CPUs_with_AVX
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.
To run our tests on Jenkins, we need to install tensorflow in the virtual environment inside the Jenkins agent. I am getting the following error.
import tensorflow as tf
File "/prod/msp/build/slave1/workspace/Jobs_uiuc_simplesilo_master-7ENH27JSQENY42PFYNEOG3SJGXLTHWJC5Z6KNZUHEDUIGUWU5ZHQ/venv2/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/prod/msp/build/slave1/workspace/Jobs_uiuc_simplesilo_master-7ENH27JSQENY42PFYNEOG3SJGXLTHWJC5Z6KNZUHEDUIGUWU5ZHQ/venv2/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/prod/msp/build/slave1/workspace/Jobs_uiuc_simplesilo_master-7ENH27JSQENY42PFYNEOG3SJGXLTHWJC5Z6KNZUHEDUIGUWU5ZHQ/venv2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/prod/msp/build/slave1/workspace/Jobs_uiuc_simplesilo_master-7ENH27JSQENY42PFYNEOG3SJGXLTHWJC5Z6KNZUHEDUIGUWU5ZHQ/venv2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/prod/msp/build/slave1/workspace/Jobs_uiuc_simplesilo_master-7ENH27JSQENY42PFYNEOG3SJGXLTHWJC5Z6KNZUHEDUIGUWU5ZHQ/venv2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/prod/msp/build/slave1/workspace/Jobs_uiuc_simplesilo_master-7ENH27JSQENY42PFYNEOG3SJGXLTHWJC5Z6KNZUHEDUIGUWU5ZHQ/venv2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: /prod/msp/build/slave1/workspace/Jobs_uiuc_simplesilo_master-7ENH27JSQENY42PFYNEOG3SJGXLTHWJC5Z6KNZUHEDUIGUWU5ZHQ/venv2/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: undefined symbol: PyUnicodeUCS4_FromString
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.
From the last line of error PyUnicodeUCS4_FromString I think this might be because of the wrong UCS type in python. However, I do not have sudo control over the Jenkins agents to install another python version. Any suggestions?
TF version : 1.6.0
Python verson: 2.7.3
I tried running tensorflow inside a Docker image on Jenkins and it worked.
I can't import tensorflow in my python CGI program on my server.
I have a VPS with CentOS6.9 operation system. I already installed gcc-4.9.0 and python3.6 so I can run python script which import tensorflow and keras.
Now I want to write a python CGI program which also import tensorflow and keras. But as soon as I add "import tensorflow as tf" my script returns a server 500 error. After removing this line of code my script runs fine. The same situation goes for keras module as well.
I googled some. It seems to be related to apache enviroment values maybe it still use gcc-4.4.7 although I already linked usr/bin/gcc to my latest gcc-4.9.0. But there are not exlaborate answer to this.
The error log on apache shows:
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/python3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/python3/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 "/usr/local/python3/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/usr/local/python3/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.7' not found (required by /usr/local/python3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 8, in <module>
import tensorflow as tf
File "/usr/local/python3/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/python3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/python3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/python3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/python3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/python3/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 "/usr/local/python3/lib/python3.6/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/usr/local/python3/lib/python3.6/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.7' not found (required by /usr/local/python3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)
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 got this error before when running the script as python script through SSH. After updating gcc on my server and change the link under 'usr/bin/gcc' I already fix it when running as python script. But somehow the apache configuration still use the old gcc. So I don't know how to configure it.