每当我尝试在 Anaconda提示上导入tensorflow时,都会出现此错误:
Traceback (most recent call last):
File "C:\Users\Dell\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Dell\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Dell\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:\Users\Dell\Anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Dell\Anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Dell\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Dell\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Dell\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Dell\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Dell\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Dell\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:\Users\Dell\Anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Dell\Anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
我尝试安装Visual C ++ 2015版本并使用“ conda install tensorflow
”重新安装tensorflow,它不断显示以下消息:
(base) C:\Users\Dell>conda install tensorflow
Collecting package metadata (repodata.json): done
Solving environment: done
已安装所有请求的软件包。
Python代码
import tensorflow as tf
答案 0 :(得分:0)
大多数这些错误是由于您首先忘记激活 anaconda提示而发生的。因此:conda activate environment_name
,后跟conda install tensorflow
,然后在anaconda提示符下键入python.exe
,启动python.exe,然后键入import tensorflow as tf
。
答案 1 :(得分:0)
我已经下载并安装了cuda v9.0和cudnn,并从提取的cudnn文件夹的bin文件夹中添加了dll文件到%path%变量中,然后我也遇到了同样的错误!