首页 > 解决方案 > 无法导入 TensorFlow 2.3

问题描述

我正在使用 Windows 10 并使用以下方法通过 Anaconda 安装了 Tensorflow:

pip install tensorflow 

使用此代码检查 tensorflow 是否安装正确:

# tensorflow
import tensorflow
print('tensorflow: %s' % tensorflow.__version__)

导入 tensorflow 时出现以下错误:

Traceback (most recent call last):
  File "C:\Users\Muril\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: Não foi possível encontrar o módulo especificado.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "deep_versions.py", line 2, in <module>
    import tensorflow
  File "C:\Users\Muril\anaconda3\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\Muril\anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
    from tensorflow.python.eager import context
  File "C:\Users\Muril\anaconda3\lib\site-packages\tensorflow\python\eager\context.py", line 35, in <module>
    from tensorflow.python import pywrap_tfe
  File "C:\Users\Muril\anaconda3\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\Muril\anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\Muril\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: Não foi possível encontrar o módulo especificado.


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.

有关如何解决此问题的任何想法?这里有一些额外的信息:

(base) C:\Users\Muril>python -V
Python 3.8.3

(base) C:\Users\Muril>pip show tensorflow
Name: tensorflow
Version: 2.3.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0

标签: tensorflow

解决方案


TF 2.6 版本的编辑代码。

import tensorflow as tf
print(tf.__version__)
print('tensorflow: %s' % tf.__version__)

推荐阅读