Pycharm中可以运行,cmd运行时报错Failed to load the native TensorFlow runtime

在pycharm中设置了Python解释器,可以正常运行Python代码。
在cmd中使用相同的解释器去运行代码报错,下面是错误信息。

Traceback (most recent call last):
  File "C:\Users\xmei\.conda\envs\text_categorization\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\xmei\.conda\envs\text_categorization\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\xmei\.conda\envs\text_categorization\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\xmei\.conda\envs\text_categorization\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\xmei\.conda\envs\text_categorization\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "G:\Text_categorization\project\system.py", line 11, in <module>
    from tcnn_model import *
  File "G:\Text_categorization\project\tcnn_model.py", line 5, in <module>
    import tensorflow as tf
  File "C:\Users\xmei\.conda\envs\text_categorization\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\xmei\.conda\envs\text_categorization\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\xmei\.conda\envs\text_categorization\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\xmei\.conda\envs\text_categorization\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\xmei\.conda\envs\text_categorization\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\xmei\.conda\envs\text_categorization\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\xmei\.conda\envs\text_categorization\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\xmei\.conda\envs\text_categorization\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

https://www.jianshu.com/p/4115338fba2d