【问题标题】:How to import GPU tensorflow in Spyder IDE (without anaconda)?如何在 Spyder IDE(没有 anaconda)中导入 GPU tensorflow?
【发布时间】:2017-04-04 11:46:14
【问题描述】:

我最近在我的 Ubuntu 16.04 上成功安装了支持 GPU 的 tensorflow,并且能够在终端中成功运行一些测试。后来我决定有一个 IDE 来编写 python 代码会更容易,我只需将 numpy 和 tensorflow 导入 IDE 并在那里运行所有内容。成功安装 Tensorflow 后,我不想再为所有内容创建另一个 Anaconda 版本,所以我直接从 Ubuntu 软件安装了 Spyder2。但是,当我尝试在 Spyder2 中导入 tensorflow 时

import tensorflow as tf

失败并显示以下消息:

ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python      
/__init__.py", line 49, 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


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.

我可以导入 numpy 没问题,但不能导入 tensorflow。我是 Linux 新手;我在这里想念什么?还是我需要 anaconda 才能使用 Spyder 和 Tensorflow?谢谢!

【问题讨论】:

  • 您的 cuda 未安装或 LD_LIBRARY_PATH 设置不正确。
  • 我确定 CUDA 已经安装,因为我可以在命令行中运行 tensorflow。我知道 LD_LIBRARY_PATH 是一个环境变量——你是说环境变量没有正确设置 Spyder 寻找 Tensorflow?如果没有,我应该如何告诉 Spyder 在哪里寻找 Tensorflow?
  • 我认为您需要从终端启动 Spyder,以便它正确获取您的环境变量(在此 LD_LIBRARY_PATH 中)。
  • 我和你有同样的问题。我在Ubuntu16.04上安装了tensorflow GPU,运行正常。但是如果我使用 PyCharm IDE,它会告诉我 ImportError: libcudart.so.8.0.

标签: python tensorflow spyder


【解决方案1】:

必须设置这些环境变量才能让 TensorFlow 知道在哪里可以找到 Cuda:

LD_LIBRARY_PATH=/usr/local/cuda/lib64
CUDA_PATH=/usr/local/cuda

【讨论】:

    猜你喜欢
    • 2020-01-10
    • 2017-06-05
    • 2021-11-08
    • 2017-08-18
    • 2018-10-09
    • 2017-05-31
    • 1970-01-01
    • 2018-01-19
    • 2023-03-10
    相关资源
    最近更新 更多