Why can I not import tensorflow-gpu on mac? - python

I am new to posting here, so forgive me if I mess something up. I have been trying for quite some time to install tensorflow with gpu support on Mac OS 10.12.6. I know Tensorflow for mac support was dropped starting in version 1.2. I am installing version 1.1.0. I was able to install this version, however, when I try to import tensorflow, I get the following stack trace:
import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/workhorse/tensorflow-gpu/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/Users/workhorse/tensorflow-gpu/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/Users/workhorse/tensorflow-gpu/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Users/workhorse/tensorflow-gpu/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/Users/workhorse/tensorflow-gpu/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/Users/workhorse/tensorflow-gpu/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: dlopen(/Users/workhorse/tensorflow-gpu/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 10): Library not loaded: #rpath/libcublas.8.0.dylib
Referenced from: /Users/workhorse/tensorflow-gpu/lib/python2.7/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 checked out the common reasons but none mentioned the one I have. Thank you for your time and help!

According to the GitHub URL there looks like there might be a fix here
According to one of the users, this seems to be a popular answer:
I just did some research I didn't really provide any insight to your answer I hope it helps if not let me know.

Related

Installing Tensorflow (cpu) on Jenkins agent

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.

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.

Tensorflow-gpu on windows: ImportError: No module named _pywrap_tensorflow

When I try to import tensorflow I get the following error:
>>import tensorflow
File "C:\Users\...\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\...\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\__init__.py", line 72, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\...\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\__init__.py", line 66, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\...\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in <module>
_pywrap_tensorflow = swig_import_helper()
File "C:\Users\...\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow')
File "C:\Users\...\Anaconda3\envs\tensorflow\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named _pywrap_tensorflow
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.
I installed the msvcp140.dll Redistributable as recommended here, but it didn't help. Any ideas? I am running Anaconda3 environment.
It turned out that tensorflow on windows requires python 3.5 or higher while my python was 2.7.8. I found out that this was the problem by the help of this great script which helps trace the source error and gives clear error messages.

Problems with installing tensorf flow on ubuntu

I installed tensorflow on Linux, but when I try to import it in the python shell it cannot find the module. I cannot find the error massage on the tensorflow website. Does anyone have any ideas on how I can fix it?
Whenever I give the command:
import tensorflow as tf
I get as a return:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/beheerder/anaconda2/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/beheerder/anaconda2/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/beheerder/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/beheerder/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/beheerder/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/beheerder/anaconda2/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: libcublas.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.
Going through your error seems like you're using anaconda for your tensorflow. I have got this error and it seems that tensorflow-gpu for anacoda is still under development and does not work properly.
I suggest you to installed the tensorflow-gpu version out of the anaconda environment. The cpu version works fine though.
After clean installing it again without anacoda for python 2.7. DO:
cd /opt/DL/tensorflow/bin/
source tensorflow-activate
Follow this as it is similar
It looks like it can't find your Cuda library. Things you want to check are:
Do you actually have a GPU? If not: reinstall the non-GPU tensorflow
Do you have Cuda version 8.0? Before you could use an older version, but since the Tensorflow 1.0 release you have to have at least version 8. Maybe reinstall Cuda to fix this problem.
Good luck!

Error importing tensorflow in simple python code with import

I am trying to run sample code in tensor flow with only one line - import tensorflow as tf. But it gives this error.
Traceback (most recent call last): File "sample.py", line 1, in <module>
import tensorflow as tf File "/home/djlimdiwala/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import * File "/home/djlimdiwala/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 72, in <module>
raise ImportError(msg) ImportError: Traceback (most recent call last): File "/home/djlimdiwala/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 61, in <module>
from tensorflow.python import pywrap_tensorflow File "/home/djlimdiwala/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper() File "/home/djlimdiwala/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description) ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory
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.
CAN ANYONE HELP IN THIS?
Focus on this part:
"ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory"
The reason why this message is displayed because Tensorflow couldn't find the place where the Nvidia cuda library is installed. Try to install it properly along with the tensorflow.
If you are using the pre-built TensorFlow binaries(included in their website https://www.tensorflow.org/install/install_linux) then please check the supported cuda and cudnn versions before installing. Those pre-built TensorFlow versions support specific versions only.
It is giving you this error because some how when you install cuda, it does not save its location in the environment.
ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory
Export the path to cuda lib:
sudo ldconfig /usr/local/cuda/lib64
cuda_version: 8.0
cuDNN_version: 5.1

Categories