2017-03-21 87 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

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

    相关问题