import tensorflow失败

现象

import tensorflow as tf

在idle和pycharm都会出现如下错误:

Traceback (most recent call last):
File "", line 1, in
import tensorflow as tf
File "C:\Users\Lenovo\Anaconda3\lib\site-packages\tensorflow_init.py", line 24, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Lenovo\Anaconda3\lib\site-packages\tensorflow\python_init
.py", line 47, in
import numpy as np
File "C:\Users\Lenovo\Anaconda3\lib\site-packages\numpy_init_.py", line 140, in
from . import _distributor_init
File "C:\Users\Lenovo\Anaconda3\lib\site-packages\numpy_distributor_init.py", line 34, in
from . import _mklinit
ImportError: DLL load failed: 找不到指定的模块。

解决

通过Anaconda Navigator/Environments的terminal启动的python terminal还是idle,都不会有这个问题
对比2种idle启动的os.getenv('PATH'),发现正常的多了3个路径:

  • C:\Users\xxx\Anaconda3
  • C:\Users\xxx\Anaconda3\Library\mingw-w64\bin
  • C:\Users\xxx\Anaconda3\Library\bin
    于是添加如上路径,正常启动的idle和pycharm就可以正常import tensorflow了

你可能感兴趣的:(import tensorflow失败)