PyCharm远程解释器和Tensorflow - >无法导入Cudart.so

问题描述 投票:3回答:3

我正在使用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上的环境变量。我认为之前它不适用于名称后面的空格( - >'LD_LIBRARY_PATH')。这里的解决方案:solution

python tensorflow pycharm remote-debugging
3个回答
4
投票

解决方案是将正确的路径添加到Pycharm环境面板:

LD_LIBRARY_PATH='/usr/local/cuda/lib64'

或者适合您配置的那个。


2
投票

您收到的错误消息是“请退出tensorflow源树,然后从那里重新启动您的python解释器。”。

通常,如果您下载tensorflow源,手动编译等安装它,然后在源文件夹中启动python并导入tensorflow,则会出现此错误消息。

您可以尝试阻止此错误: - 检查tensorflow源是否在您运行远程应用程序的文件夹中(您是否按照这样的方式使其正常工作?http://www.pinchofintelligence.com/faster-writing-and-testing-machine-learning-applications/) - 尝试查找并删除tensorflow源文件夹 - 重新启动你的电脑(这会清除你正在运行你的东西的/ tmp文件夹)

希望其中一件有用,请告诉我!


0
投票

远程nvidia-docker案例

我花了几个小时来解决类似的问题。我实际上已经多次读取stackoverflow并且毫不费力地添加所有这些env变量。

所以,如果你有远程nvidia-docker与oppened ssh然后读这个线程:https://github.com/bethgelab/docker/issues/5

当您使用ssh连接时,nvidia-docker会错误地启动终端。

Pycharm实际上使用ssh连接进行远程调试,因此它也无法启动tensorflow-gpu

© www.soinside.com 2019 - 2024. All rights reserved.