2017-03-21 141 views
0

我在運行Ubuntu 16.04的系統上安裝了tensorflow-gpuimport tensorflow工作正常,在終端上的python CLI和IPython上加載CUDA。但在導入IPython QtConsole時,出現以下錯誤。在Python CLI和IPython CLI中導入TensorFlow但不在IPython中QtConsole

ImportErrorTraceback (most recent call last) 
<ipython-input-25-41389fad42b5> in <module>() 
----> 1 import tensorflow as tf 

/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py in <module>() 
    22 
    23 # pylint: disable=wildcard-import 
---> 24 from tensorflow.python import * 
    25 # pylint: enable=wildcard-import 
    26 

/usr/local/lib/python2.7/dist-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 "/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. 

提到的URL是一個死鏈接。

我檢查了QtConsole的環境變量,它沒有在我的.bashrc文件中做的修改。我通過使用!export $ENV_VAR=VALUE來更改變量。我後來嘗試!echo $PATH,但沒有反映變化。奇怪的O_o

我試過更換os.environ字典。這反映了我的變化,但仍然無法導入tensorflow 如何解決此問題?

編輯: 1.導入上Jupyter筆記本tensorflow工程,以及,但不是在IPython的QtConsole

  • 我試圖運行作爲jupyter qtconsole代替ipython qtconsole,相同的錯誤消息
  • 回答

    1

    當我試圖在Jupyter筆記本上運行啓用GPU的Tensorflow時,我遇到了同樣的問題。我不得不解決兩件事,也許他們也幫助你。

    Jupyter內核

    確保您jupyter內核是一樣的你VENV/Python環境計劃運行。你可以發現,從運行

    $ jupyter kernelspec list 
    

    如果不是(我指着.LOCAL /股/ jupyter /粒/),則有固定它的兩個方面。

    1)您可以編輯kernel.json文件指向你想要的Python:

    $ vim jupyter/kernels/python2/kernel.json 
    

    2)您可以通過運行刪除您VENV默認的內核:

    $ jupyter kernelspec remove python2 
    

    這將默認在您的venv上使用所需的python。

    Tensorflow安裝錯誤

    的pywrap導入錯誤是knwon issue.。因爲我不想用我的安裝染指(因爲它工作得很好的蟒蛇CLI,只是沒有上Jupyter),只爲我工作的建議是:

    $ export PBR_VERSION=<your pbr version number> 
    

    這似乎是一個問題mock的setup.cfg,這可能會在以後的版本中解決。

    Goodluck!

    +0

    我已經刪除了內核,可否詳細說明'PBR'部分? 我不知道那是什麼或如何找到pbr版本('pbr。__version__')給我一個錯誤 –

    +0

    你可以從你的venv運行'pip list'來檢查哪個版本的pbr正在運行。然後,您可以通過執行[this]這一行來將export語句添加到您的bash配置文件中(https://stackoverflow.com/questions/14524590/how-to-add-export-statement-in-a-bash-輪廓文件?RQ = 1)。 我不得不將'export PBR_VERSION = 3.1.1'添加到我的bashrc中以使其工作。希望這有助於你! – naki

    +0

    它的工作原理!非常感謝 :) –

    相關問題