简体   繁体   English

在带有导入的简单python代码中导入tensorflow时出错

[英]Error importing tensorflow in simple python code with import

I am trying to run sample code in tensor flow with only one line - import tensorflow as tf. 我正在尝试仅使用一行在张量流中运行示例代码-将tensorflow导入为tf。 But it gives this error. 但是它给出了这个错误。

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.

CAN ANYONE HELP IN THIS? 有人可以帮忙吗?

Focus on this part: "ImportError: libcudart.so.8.0: cannot open shared object file: No such file or directory" 专注于这一部分:“ ImportError:libcudart.so.8.0:无法打开共享对象文件:没有这样的文件或目录”

The reason why this message is displayed because Tensorflow couldn't find the place where the Nvidia cuda library is installed. 之所以显示此消息,是因为Tensorflow找不到Nvidia cuda库的安装位置。 Try to install it properly along with the tensorflow. 尝试将其与tensorflow一起正确安装。

If you are using the pre-built TensorFlow binaries(included in their website https://www.tensorflow.org/install/install_linux ) then please check the supported cuda and cudnn versions before installing. 如果您正在使用预构建的TensorFlow二进制文件(包含在其网站https://www.tensorflow.org/install/install_linux中 ),则在安装之前请检查受支持的cuda和cudnn版本。 Those pre-built TensorFlow versions support specific versions only. 这些预先构建的TensorFlow版本仅支持特定版本。

It is giving you this error because some how when you install cuda, it does not save its location in the environment. 它给您这个错误的原因是,某些在您安装cuda时如何将其保存在环境中的位置。

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

Export the path to cuda lib: 将路径导出到cuda lib:

sudo ldconfig /usr/local/cuda/lib64

cuda_version: 8.0 cuda_version:8.0

cuDNN_version: 5.1 cuDNN_version:5.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM