2016-11-30 120 views
3

我安装之后从tensorflow网页上的指示tensorflow,使用以下命令:为什么我不能导入tensorflow

sudo apt-get install python-pip python-dev 
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.0rc0-cp27-none-linux_x86_64.whl 
sudo pip install --upgrade $TF_BINARY_URL 

然后我运行python和类型:

import tensorflow 

我得到这些错误信息:

ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory 
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. 

我有谷歌这个问题,并找到答案像https://github.com/tensorflow/tensorflow/issues/1244https://github.com/NVIDIA/DIGITS/issues/8 但他们都没有帮助我的问题。 我的python版本是2.7.6。我正在安装Linux的纯CPU版本。 当我第一次以上述方式安装tensorflow,它工作正常,我设法运行一些教程示例。但是今天我试图安装anaconda,这是另一个有用的计算工具箱。当我安装它时,我发现没有张量流。所以我再次使用conda安装tensorflow。但是,然后发生上述错误。现在我已经移除了anaconda,并且移除了anaconda添加的环境路径。但导入错误仍未解决。 我对发生了什么感到困惑。谢谢大家的亲切帮助!

回答

1
ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory 

这表明正在导入tensorflow的GPU版本。也许你已经安装了另一个版本的tensorflow?如果你用pip安装所有的python包,你可以通过列出已安装的包来进行检查。

+0

这里来了奇怪的事情。正如我在问题中所展示的那样,我确实下载了仅限CPU的版本。但它报告了这个消息。 – pfc

+0

我看到,已更新。 – ben

+0

谢谢您的信息。我检查了python的sys.path。我发现有一个包含张量流的路径“/home/myname/.local/lib”。我不知道它是如何出现在那里的。我认为这是导致Python搜索tensorflow的不正确版本的路径。我可以通过运行“sys.path.remove()”来删除此路径。但是这只能暂时消除路径。你知道我可以永久删除吗?我一直在寻找答案,但还没有找到答案。再次感谢你!!! – pfc

0

在/etc/ld.so.conf.d/创建.conf文件:

sudo nano /etc/ld.so.conf.d/nvidia.conf

补充一点:

/usr/local/cuda-8.0/lib64 
/usr/local/cuda-8.0/lib # you probably don't need this line; check 
         # if the directory exists 

然后运行sudo ldconfig。希望这给你带来快乐。