Skip to main content
 首页 » 编程设计

python之如何在 Spyder IDE(没有 anaconda)中导入 GPU tensorflow

2025年02月15日32langtianya

我最近在我的 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?谢谢!

请您参考如下方法:

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

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