无法在 Jupyter 笔记本中导入 TensorFlow



每当试图导入像tensorflow这样的深度学习库时,keras显示错误

import tensorflow

ImportError                               Traceback (most recent call last)
~anaconda3libsite-packagestensorflowpythonpywrap_tensorflow.py in <module>
63   try:
---> 64     from tensorflow.python._pywrap_tensorflow_internal import *
65   # This try catch logic is because there is no bazel equivalent for py_extension.
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: A dynamic link library (DLL) initialization routine failed.
During handling of the above exception, another exception occurred:
ImportError                               Traceback (most recent call last)
<ipython-input-3-370f0fe8bb94> in <module>
----> 1 import tensorflow
~anaconda3libsite-packagestensorflow__init__.py in <module>
39 import sys as _sys
40 
---> 41 from tensorflow.python.tools import module_util as _module_util
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
43 
~anaconda3libsite-packagestensorflowpython__init__.py in <module>
37 # go/tf-wildcard-import
38 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
---> 39 from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
40 
41 from tensorflow.python.eager import context
~anaconda3libsite-packagestensorflowpythonpywrap_tensorflow.py in <module>
81 for some common reasons and solutions.  Include the entire stack trace
82 above this error message when asking for help.""" % traceback.format_exc()
---> 83   raise ImportError(msg)
84 
85 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long
ImportError: Traceback (most recent call last):
File "C:UsersGokulanaconda3libsite-packagestensorflowpythonpywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: A dynamic link library (DLL) initialization routine failed.

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.

在搜索您的问题时,我发现了以下内容:

  1. https://github.com/tensorflow/tensorflow/issues/23683
  2. ImportError:DLL加载失败:动态链接库(DLL(初始化例程失败

在我看来,如果您使用pip安装tensorflow,并使用conda重新安装,请卸载它。

conda install -c anaconda tensorflow

如果需要,请修改为tensorflow-gpu,在执行上述命令之前,请确保在conda中创建了一个新的环境。请勿安装在基础中!

最新更新