Traceback (most recent call last): File "C:/Users/azwraith/PycharmProjects/paddle/test.py", line 2, in import paddle.fluid as fluid File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\paddle\fluid\__init__.py", line 57, in from . import contrib File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\paddle\fluid\contrib\__init__.py", line 27, in from . import slim File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\paddle\fluid\contrib\slim\__init__.py", line 15, in from .core import * File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\paddle\fluid\contrib\slim\core\__init__.py", line 15, in from . import config File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\paddle\fluid\contrib\slim\core\config.py", line 19, in from ..prune import * File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\paddle\fluid\contrib\slim\prune\__init__.py", line 17, in from . import prune_strategy File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\paddle\fluid\contrib\slim\prune\prune_strategy.py", line 22, in from scipy.optimize import leastsq File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\scipy\optimize\__init__.py", line 390, in from ._minimize import * File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\scipy\optimize\_minimize.py", line 30, in from ._trustregion_constr import _minimize_trustregion_constr File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\scipy\optimize\_trustregion_constr\__init__.py", line 4, in from .minimize_trustregion_constr import _minimize_trustregion_constr File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\scipy\optimize\_trustregion_constr\minimize_trustregion_constr.py", line 4, in from scipy.sparse.linalg import LinearOperator File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\scipy\sparse\linalg\__init__.py", line 116, in from .eigen import * File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\scipy\sparse\linalg\eigen\__init__.py", line 11, in from .arpack import * File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\scipy\sparse\linalg\eigen\arpack\__init__.py", line 22, in from .arpack import * File "C:\Users\azwraith\Anaconda3\envs\paddle\lib\site-packages\scipy\sparse\linalg\eigen\arpack\arpack.py", line 45, in from . import _arpack ImportError: DLL load failed: 找不到指定的程序。
从一个BUG入手,研究python的import机制
先简单描述下问题,在Pycharm中,使用conda虚拟环境paddle,始终报错
怀疑是pycharm的问题,于是从conda中启动paddle环境,发现运行正常,又直接从cmd中调用paddle的python程序,发现还是报这个错误
于是了解了下import机制
import机制详解:https://blog.csdn.net/weixin_38256474/article/details/81228492
有一个需要注意的点是相对路径
from . import *
Note that relative imports are based on the name of the current module. Since the name of the main module is always"__main__", modules intended for use as the main module of a Python application must always use absolute imports.
这句话应该解释得很清楚了
然后继续研究我们的问题呢...突然想到,不如把环境变量打出来看看吧
cmd中使用set命令,然后copy到sublime中比较,把;替换为\n就能很好的观察
emmmm,答案很显然了,pycharm和我犯了一样的错误,虽然调用的是paddle环境的python,但是并没有activate paddle的environment
暂时没找到pycharm给solution,解决办法比较蠢
新建了一个快捷方式emmm,里面切换环境再启动pycharm
C:\Windows\System32\cmd.exe /K "activate paddle&"D:\Program Files\JetBrains\PyCharm 2017.3.1\bin\pycharm64.exe""