如何修复python 3.7.1上的Import TensorFlow错误?

时间:2019-08-06 15:33:06

标签: python python-3.x tensorflow neural-network conv-neural-network

我正在研究 darkflow上的YOLO对象检测。导入tensorflow确实会弹出错误,并且错误如下。我已经安装了 CUDA 10.0和cuDNN 7.5 for 10.0 ,仍然有这个问题,不知道为什么,我已经尝试了所有可能的解决方案。

我的系统是 ASUS GL-502VS GTX1070

>import tensorflow as tf
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in 
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in 
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.

>During handling of the above exception, another exception occurred:

>Traceback (most recent call last):
File "", line 1, in 
File "C:\Anaconda3\lib\site-packages\tensorflow_init_.py", line 24, in 
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Anaconda3\lib\site-packages\tensorflow\python_init_.py", line 49, in 
from tensorflow.python import pywrap_tensorflow
File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in 
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in 
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in 
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.

2 个答案:

答案 0 :(得分:0)

在运行脚本之前尝试一下:

export CUDA_HOME=/usr/bin/cuda # or /usr/bin/cuda-10, it depends on your installation
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$CUDA_HOME/lib64

答案 1 :(得分:0)

首先要打开您的cmd(windows)或终端机(Linux),并在那里打开python,然后导入tensorflow import tensorflow,然后如果导入它并运行良好,则说明您设置了错误的python解释器您的项目或您当前的解释器没有安装tensorflow。然后以防万一请更改解释器或为该解释器安装tensorflow。