我试图在我的Anaconda docker容器中使用TensorFlow,我得到了错误:
导入tensorflow时出错 . 除非您使用bazel,否则不应尝试从其源目录导入tensorflow;请退出tensorflow源代码树,然后从那里重新启动python解释器 .
但是,我不知道源目录甚至意味着什么 . 源目录是什么意思,从中导入tensorflow是什么意思?为什么这样做不好?
我只是这样做:
nvidia-docker run -ti --rm continuumio/anaconda3 bash
然后在我正在做的容器内:
pip install tensorflow-gpu
然后我转到python3解释器并在导入tensorflow后得到该错误 .
为完整起见,完整的错误消息是:
root@01452be96fe9:/# python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', 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: libcudart.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 60, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', 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: libcudart.so.8.0: cannot open shared object file: No such file or directory
Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.
3 回答
源目录是包含TensorFlow安装的目录 . Python因为它在本地看到TensorFlow源文件而不仅仅是在_2536113中这一事实而感到困惑 . 该错误消息要求您从安装TensorFlow的目录以外的位置运行解释程序 .
试试
export LD_LIBRARY_PATH=/usr/local/cuda/lib64
来源:http://withr.me/install-tensorflow-ubuntu-16-04/
确保您使用的是python 3.5.3!其他版本可能不起作用!