我正在使用PyCharm进行远程调试,客户端Win10,服务器Ubuntu 16.在Ubuntu机器上,我正确安装了Cuda 8.0,以及python 2.7和tensorflow 1.0.0。 Tensorflow完美地从服务器上运行(ssh +调用python,导入tensorflow等...)。
在PyCharm中我为我的服务器机器设置了一个远程调试器,但是现在导入tensorflow会导致错误:
Traceback (most recent call last):
File "/home/*****/*****/********/*******.py", line 24, in <module>
import tensorflow as tf
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 60, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python2.7/dist-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
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.
我试过了:
将正确的路径添加到sys.path变量
将LD_LIBRARY_PATH添加到os.environ和/或PyCharm环境变量
没有成功!
我记得很久以前我能够毫无问题地进行调试,但我无法弄清楚出了什么问题。有什么建议吗?
更新1 重新启动后,错误已更改为此
ssh://****@192.168.***.***:22/usr/bin/python -u /home/*****/.pycharm_helpers/pydev/pydevd.py --multiproc --qt-support --client '0.0.0.0' --port 35523 --file /home/*/*/*/*/test.py
warning: Debugger speedups using cython not found. Run '"/usr/bin/python" "/home/*/.pycharm_helpers/pydev/setup_cython.py" build_ext --inplace' to build.
pydev debugger: process 1913 is connecting
Connected to pydev debugger (build 163.10154.50)
Traceback (most recent call last):
File "/home/*/.pycharm_helpers/pydev/pydevd.py", line 1596, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/*/.pycharm_helpers/pydev/pydevd.py", line 974, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/*/*/*/*/test.py", line 1, in <module>
import tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 72, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 61, in <module>
from tensorflow.python import pywrap_tensorflow
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python2.7/dist-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.
Process finished with exit code 1
更新2 /已解决 正如我之前尝试过的,解决方案是在配置面板上将LD_LIBRARY_PATH添加到pycharm上的环境变量。我认为之前它不适用于名称后的空格( - &gt;'LD_LIBRARY_PATH')。这里的解决方案: solution
答案 0 :(得分:4)
解决方案是将正确的路径添加到Pycharm环境面板:
LD_LIBRARY_PATH='/usr/local/cuda/lib64'
或适合您配置的那个。
答案 1 :(得分:2)
您收到的错误消息是&#34;请退出tensorflow源代码树,然后从那里重新启动您的python解释器。&#34;。
如果您下载tensorflow源,手动编译等安装它,然后在源文件夹中启动python并导入tensorflow,通常会收到此错误消息。
您可以尝试阻止此错误: - 检查tensorflow源是否在您运行远程应用程序的文件夹中(您是否按照这样的方式使其正常工作?http://www.pinchofintelligence.com/faster-writing-and-testing-machine-learning-applications/) - 尝试查找并删除tensorflow源文件夹 - 重新启动你的电脑(这会清除你正在运行你的东西的/ tmp文件夹)
希望其中一件事有效,请告诉我!
答案 2 :(得分:0)
远程nvidia-docker案例
我花了几个小时来解决类似的问题。我实际上多次阅读了stackoverflow,并毫不费力地添加了所有这些env变量。
因此,如果您的远程nvidia-docker安装了ssh,请阅读以下主题: https://github.com/bethgelab/docker/issues/5
nvidia-docker在与ssh连接时无法正确启动终端。
Pycharm实际上使用ssh进行连接以进行远程调试,因此它也无法启动tensorflow-gpu