Spyder - 导入 tensorflow 出错

Spyder - Importing tensorflow gives an error

我正在尝试加载一个 tensorflow 项目。它将使用 GPU

每次我导入tensorflow我都会得到一个错误:

sys.path
Out[5]: 
['',
 '/usr/local/lib/python2.7/dist-packages/spyder/utils/site',
 '/usr/local/cuda/lib64',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/local/lib/python2.7/dist-packages/IPython/extensions',
 '/home/kevin/.ipython']

import tensorflow
Traceback (most recent call last):

  File "<ipython-input-6-a649b509054f>", 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 49, in <module>
    from tensorflow.python import pywrap_tensorflow

  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)

ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcudnn.so.5: 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.

问题是我在文件夹 /usr/local/cuda/lib64

中确实有文件 (libcudnn.so.5)

ls /usr/local/cuda/lib64/ lib64/ libcudnn.so.5@ libcudnn.so.6.0.21* libcudnn.so@libcudnn.so.6@libcudnn_static.a

令我沮丧的是,我实际上可以直接从终端中的 ipython 和终端中的常规 python shell 加载 tensorflow。我的 .bashrc 中有这个:export LD_LIBRARY_PATH=/usr/local/cuda/lib64/

但是spyder中的pythonshell和ipythonshell好像都没有看到路径?知道我能做什么吗?我已经在 spyder 中添加了 PYTHONPATH 管理器的路径。我还将数学添加到我的主文件夹中的 .profile

(Spyder developer here)您需要从系统终端启动Spyder才能解决这个问题。

发生这种情况是因为当 Spyder 从 Unity 启动时,它不会获取终端中定义的环境变量。