使用命令提示符导入tensorflow时出现问题

时间:2020-03-29 16:20:53

标签: python tensorflow pip

>>> import tensorflow
Traceback (most recent call last):
  File "C:\Users\varsh\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\varsh\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\varsh\venv\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\varsh\appdata\local\programs\python\python36\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "c:\users\varsh\appdata\local\programs\python\python36\lib\imp.py", line 343, 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\varsh\venv\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\varsh\venv\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\varsh\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\varsh\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\varsh\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\varsh\venv\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\varsh\appdata\local\programs\python\python36\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "c:\users\varsh\appdata\local\programs\python\python36\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.


Failed to load the native TensorFlow runtime.

1 个答案:

答案 0 :(得分:0)

我建议您使用以下命令显示tensorflow是否正确安装:

pip show tensorflow

U将获得类似以下输出:

Name: tensorflow
Version: 2.1.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/

如果没有任何输出,则可能未正确安装。

尝试使用进行卸载:

pip uninstall tensorflow

然后尝试重新安装。