2017-02-16 76 views
1

我正在嘗試導入TensorFlow,但最終出現此錯誤。在Jupyter Notebook中導入TensorFlow GPU時出錯

ImportError        Traceback (most recent call last) 
/Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/python/__init__.py in <module>() 
    60  sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL) 
---> 61  from tensorflow.python import pywrap_tensorflow 
    62  sys.setdlopenflags(_default_dlopen_flags) 

/Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py in <module>() 
    27    return _mod 
---> 28  _pywrap_tensorflow = swig_import_helper() 
    29  del swig_import_helper 

/Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py in swig_import_helper() 
    23    try: 
---> 24     _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description) 
    25    finally: 

/Users/Aakaash/miniconda3/lib/python3.5/imp.py in load_module(name, file, filename, details) 
    241   else: 
--> 242    return load_dynamic(name, filename, file) 
    243  elif type_ == PKG_DIRECTORY: 

/Users/Aakaash/miniconda3/lib/python3.5/imp.py in load_dynamic(name, path, file) 
    341    name=name, loader=loader, origin=path) 
--> 342   return _load(spec) 
    343 

ImportError: dlopen(/Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: @rpath/libcudart.8.0.dylib 
    Referenced from: /Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so 
    Reason: image not found 

During handling of the above exception, another exception occurred: 

ImportError        Traceback (most recent call last) 
<ipython-input-7-a649b509054f> in <module>() 
----> 1 import tensorflow 

/Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/__init__.py in <module>() 
    22 
    23 # pylint: disable=wildcard-import 
---> 24 from tensorflow.python import * 
    25 # pylint: enable=wildcard-import 
    26 

/Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/python/__init__.py in <module>() 
    70 for some common reasons and solutions. Include the entire stack trace 
    71 above this error message when asking for help.""" % traceback.format_exc() 
---> 72 raise ImportError(msg) 
    73 
    74 # Protocol buffers 

ImportError: Traceback (most recent call last): 
    File "/Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 61, in <module> 
    from tensorflow.python import pywrap_tensorflow 
    File "/Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module> 
    _pywrap_tensorflow = swig_import_helper() 
    File "/Users/Aakaash/miniconda3/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 "/Users/Aakaash/miniconda3/lib/python3.5/imp.py", line 242, in load_module 
    return load_dynamic(name, filename, file) 
    File "/Users/Aakaash/miniconda3/lib/python3.5/imp.py", line 342, in load_dynamic 
    return _load(spec) 
ImportError: dlopen(/Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): Library not loaded: @rpath/libcudart.8.0.dylib 
    Referenced from: /Users/Aakaash/miniconda3/lib/python3.5/site-packages/tensorflow/python/_pywrap_tensorflow.so 
    Reason: image not found 


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. 

我能夠導入TensorFlow的CPU版本沒有問題。我也能夠從終端啓動的Python控制檯中導入TensorFlow。在Console和Jupyter Notebook中,Python可執行文件的路徑是相同的(sys.executable在Console和Jupyter Notebook中給出了相同的輸出)。

TensorFlow版本 - 1.0.0

Python版本 - 3.5.2

Cuda的版本 - 8.0

+0

這看起來像是一個安裝問題,我們跟蹤我們的github問題頁面。請在那裏提交問題。根本問題是您的環境無法找到cuda庫。請適當設置'LD_LIBRARY_PATH'。你可以在'_pywrap_tensorflow.so'對象上運行'ldd'來檢查你是否正確。 – drpng

+0

好的。我將在Github上提出一個問題。你能告訴我如何正確設置LD_LIBRARY_PATH嗎?我對此很陌生,我不知道該怎麼做。 –

+0

請按照[安裝指南](https://www.tensorflow.org/install/install_linux)進行操作。它有一個指向NVIDIA文檔的指針。 – drpng

回答

0

貌似錯誤是,當我安裝CUDA和CuDNN。遵循Nvidia提供的指南,它告訴我爲Mac OS X設置DYLD_LIBRARY_PATH的路徑。不幸的是,使用Jupyter Notebook時這不起作用。我們需要按照Nvidia指南的Linux步驟並設置LD_LIBRARY_PATH。這解決了這個問題。

0

在我的情況下,啓動Jupyter筆記本時,即使在Ubuntu上輸出它.bashrc.profileLD_LIBRARY_PATH也被清除。只有啓動筆記本服務器env VARIABLE=$VARIABLE jupyter notebook解決了它。