首页 > 解决方案 > 无法在 jupyter notebook 中导入 tensorflow

问题描述

每当尝试导入 tensorflow 等深度学习库时,keras 都会显示错误

import tensorflow

ImportError                               Traceback (most recent call last)
~\anaconda3\lib\site-packages\tensorflow\python\pywrap_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

~\anaconda3\lib\site-packages\tensorflow\__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 

~\anaconda3\lib\site-packages\tensorflow\python\__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

~\anaconda3\lib\site-packages\tensorflow\python\pywrap_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:\Users\Gokul\anaconda3\lib\site-packages\tensorflow\python\pywrap_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.

标签: pythontensorflowmachine-learningkeras

解决方案


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

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

在我看来,卸载 tensorflow,如果你已经使用它pip安装并使用conda.

conda install -c anaconda tensorflow

修改为tensorflow-gpu以防万一,在执行上述命令之前,请确保您已在conda. 不要安装在底座上!


推荐阅读