【问题标题】:Why can't I import tensorflow为什么我不能导入张量流
【发布时间】:2016-11-30 13:46:43
【问题描述】:

我按照 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/1244 的答案 和 https://github.com/NVIDIA/DIGITS/issues/8 但它们都对我的问题没有帮助。 我的 python 版本是 2.7.6。我正在为 Linux 安装仅限 CPU 的版本。 当我第一次以上述方式安装 tensorflow 时,它工作正常,并且我设法运行了一些教程示例。但是今天我尝试安装 anaconda,这是另一个有用的计算工具箱。安装的时候发现没有tensorflow了。所以我再次使用 conda 安装了 tensorflow。但是随后发生了上述错误。现在我已经移除了anaconda,并且移除了anaconda添加的环境路径。但是导入错误仍未解决。 我对发生的事情感到困惑。谢谢大家的热心帮助!!!!

【问题讨论】:

    标签: python tensorflow anaconda


    【解决方案1】:
    ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory
    

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

    【讨论】:

    • 奇怪的事情来了。正如我在问题中所展示的,我确实下载了仅限 CPU 的版本。但它报告了这条消息。
    • 感谢您的信息。我检查了python的sys.path。我发现有一个包含张量流的路径“/home/myname/.local/lib”。我不知道它是怎么出现在那里的。我认为正是这条路径导致 python 搜索不正确的 tensorflow 版本。我可以通过运行“sys.path.remove()”来删除这个路径。但这只能暂时删除路径。你知道我怎样才能永久删除它吗?我一直在寻找答案,但还没有找到。再次感谢!!!
    • 此外,我不想通过“rm -rf”直接删除这个路径,以防有其他程序依赖它。我希望从python的搜索空间中删除路径。
    • 您可以修改 PYTHONPATH 变量来实现这一点 (docs.python.org/3/using/cmdline.html)
    【解决方案2】:

    在 /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。希望这能给你带来快乐。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2018-08-30
      • 2020-12-23
      • 2018-01-12
      • 2021-11-24
      • 2020-04-24
      相关资源
      最近更新 更多