使用imp在简单python代码中导入tensorflow时出错

2024-05-08 00:12:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在tensor flow中运行示例代码,只使用一行代码-将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.

有人能帮忙吗?在


Tags: inpyimporthomeinitlibpackageslocal
2条回答

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

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

将路径导出到cuda lib:

^{pr2}$

cuda_version: 8.0

cuDNN_version: 5.1

关注这一部分: “恐怖分子:利库达特.8.0:无法打开共享对象文件:没有此类文件或目录“

显示此消息的原因是Tensorflow找不到Nvidia cuda库的安装位置。试着把它和tensorflow一起安装好。在

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

相关问题 更多 >