我试图在我的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.
答案 0 :(得分:0)
源目录是包含TensorFlow安装的目录。 Python在本地看到TensorFlow源文件而不仅仅是PYTHONPATH
这个事实让人感到困惑。错误消息要求您从安装TensorFlow的目录以外的位置运行解释器。
答案 1 :(得分:0)
尝试使用export LD_LIBRARY_PATH=/usr/local/cuda/lib64
答案 2 :(得分:0)
确保您使用的是python 3.5.3!其他版本可能无效!