使用import导入简单python代码中的tensorflow时出错

时间:2017-03-12 11:26:24

标签: python ubuntu tensorflow

我试图在张量流中只用一行运行示例代码 - 导入张量流为tf。但它给出了这个错误。

Traceback (most recent call last):   File "sample.py", line 1, in <module>
    import tensorflow as tf   File "/home/djlimdiwala/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *   File "/home/djlimdiwala/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 72, in <module>
    raise ImportError(msg) ImportError: Traceback (most recent call last):   File "/home/djlimdiwala/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow   File "/home/djlimdiwala/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()   File "/home/djlimdiwala/.local/lib/python2.7/site-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.

任何人都可以帮助吗?

2 个答案:

答案 0 :(得分:0)

关注这一部分: “ImportError:libcudart.so.8.0:无法打开共享对象文件:没有这样的文件或目录”

显示此消息的原因是因为Tensorflow无法找到安装Nvidia cuda库的位置。尝试将其与张量流一起正确安装。

如果您使用预先构建的TensorFlow二进制文件(包含在其网站https://www.tensorflow.org/install/install_linux中),请在安装之前检查支持的cuda和cudnn版本。这些预先构建的TensorFlow版本仅支持特定版本。

答案 1 :(得分:0)

它给你这个错误,因为你在安装cuda的时候,它没有保存它在环境中的位置。

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

将路径导出到cuda lib:

sudo ldconfig /usr/local/cuda/lib64
  

cuda_version:8.0

     

cuDNN_version:5.1