在eclipse中导入tensorflow失败

在eclipse中导入tensorflow失败,tensorflow,Tensorflow,在Mac上安装tensorflow for python3.5,请尝试以下测试代码: import tensorflow as tf hello = tf.constant("test") sess = tf.Session() print(sess.run(hello)) 从终端运行时,它正在工作。 但如果我从eclipse运行它,将出现以下异常: warning: Debugger speedups using cython not found. Run '"/usr/local/bin

在Mac上安装tensorflow for python3.5,请尝试以下测试代码:

import tensorflow as tf

hello = tf.constant("test")
sess = tf.Session()
print(sess.run(hello))
从终端运行时,它正在工作。 但如果我从eclipse运行它,将出现以下异常:

warning: Debugger speedups using cython not found. Run '"/usr/local/bin/python3.5" "/Users/leitian/.p2/pool/plugins/org.python.pydev_5.3.0.201610121612/pysrc/setup_cython.py" build_ext --inplace' to build.
pydev debugger: starting (pid: 2109)
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/local/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: dlopen(/usr/local/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: @rpath/libcudart.8.0.dylib
  Referenced from: /usr/local/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so
  Reason: image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/leitian/.p2/pool/plugins/org.python.pydev_5.3.0.201610121612/pysrc/pydevd.py", line 1531, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Users/leitian/.p2/pool/plugins/org.python.pydev_5.3.0.201610121612/pysrc/pydevd.py", line 938, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/leitian/.p2/pool/plugins/org.python.pydev_5.3.0.201610121612/pysrc/_pydev_imps/_pydev_execfile.py", line 25, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/leitian/code/python/eclipse-ws/TestTF/Hello.py", line 1, in <module>
    import tensorflow as tf
  File "/usr/local/lib/python3.5/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 60, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/local/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: dlopen(/usr/local/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: @rpath/libcudart.8.0.dylib
  Referenced from: /usr/local/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so
  Reason: image not found


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.
警告:找不到使用cython的调试器加速。运行'/usr/local/bin/python 3.5”“/Users/leitian/.p2/pool/plugins/org.python.pydev_5.3.0.201610121612/pysrc/setup_cython.py“build\u ext--inplace”进行构建。
pydev调试器:正在启动(pid:2109)
回溯(最近一次呼叫最后一次):
文件“/usr/local/lib/python3.5/site packages/tensorflow/python/_init__.py”,第49行,在
从tensorflow.python导入pywrap\u tensorflow
文件“/usr/local/lib/python3.5/site packages/tensorflow/python/pywrap_tensorflow.py”,第28行,在
_pywrap\u tensorflow=swig\u import\u helper()
swig\u import\u helper中的文件“/usr/local/lib/python3.5/site packages/tensorflow/python/pywrap\u tensorflow.py”,第24行
_mod=imp.load_模块(“pywrap_tensorflow”,fp,路径名,描述)
load_模块中的文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py”,第242行
返回加载动态(名称、文件名、文件)
文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py”,第342行,在load\u dynamic中
返回负载(规格)
导入错误:dlopen(/usr/local/lib/python3.5/site-packages/tensorflow/python//u pywrap\u tensorflow.so,10):未加载库:@rpath/libcudart.8.0.dylib
引用自:/usr/local/lib/python3.5/site-packages/tensorflow/python//u pywrap\u tensorflow.so
原因:找不到图像
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/Users/leitian/.p2/pool/plugins/org.python.pydev_5.3.0.201610121612/pysrc/pydevd.py”,第1531行,在
globals=debugger.run(setup['file'],None,None,is_模块)
文件“/Users/leitian/.p2/pool/plugins/org.python.pydev_5.3.0.201610121612/pysrc/pydevd.py”,第938行,正在运行
pydev_imports.execfile(文件、全局、局部)#执行脚本
文件“/Users/leitian/.p2/pool/plugins/org.python.pydev_5.3.0.201610121612/pysrc/_pydev_imps/_pydev_execfile.py”,execfile中的第25行
exec(编译(内容+“\n”,文件,'exec'),全局,loc)
文件“/Users/leitian/code/python/eclipsews/TestTF/Hello.py”,第1行,在
导入tensorflow作为tf
文件“/usr/local/lib/python3.5/site packages/tensorflow/_init__.py”,第24行,在
从tensorflow.python导入*
文件“/usr/local/lib/python3.5/site packages/tensorflow/python/_init__.py”,第60行,在
提高效率(msg)
ImportError:回溯(最近一次呼叫上次):
文件“/usr/local/lib/python3.5/site packages/tensorflow/python/_init__.py”,第49行,在
从tensorflow.python导入pywrap\u tensorflow
文件“/usr/local/lib/python3.5/site packages/tensorflow/python/pywrap_tensorflow.py”,第28行,在
_pywrap\u tensorflow=swig\u import\u helper()
swig\u import\u helper中的文件“/usr/local/lib/python3.5/site packages/tensorflow/python/pywrap\u tensorflow.py”,第24行
_mod=imp.load_模块(“pywrap_tensorflow”,fp,路径名,描述)
load_模块中的文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py”,第242行
返回加载动态(名称、文件名、文件)
文件“/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/imp.py”,第342行,在load\u dynamic中
返回负载(规格)
导入错误:dlopen(/usr/local/lib/python3.5/site-packages/tensorflow/python//u pywrap\u tensorflow.so,10):未加载库:@rpath/libcudart.8.0.dylib
引用自:/usr/local/lib/python3.5/site-packages/tensorflow/python//u pywrap\u tensorflow.so
原因:找不到图像
导入tensorflow时出错。除非你用的是bazel,
您不应该尝试从其源目录导入tensorflow;
请退出tensorflow源代码树,并重新启动python解释器
从那里开始。
有人能帮忙吗?
非常感谢。

我无法帮助您解决Eclipse问题,但错误消息意味着找不到Tensorflow共享库。解决此问题的一种方法是将环境变量
DYLD\u LIBRARY\u PATH
设置为指向包含
\u pywrap\u tensorflow.so的目录。希望有帮助!我找到了原因:我错误地安装了GPU版本,但它没有被完全删除。