Python:从cygwin运行有效,而从PyCharm运行则不然



我可以成功运行使用的python脚本

from sklearn.cluster import DBSCAN

来自64位cygwin终端提示符,该提示符使用64位python 2.7构建。

当我使用-vv解释器选项从64位和32位pycharm运行相同的程序时,我得到(前2行是详细输出):

import numpy.linalg.linalg # precompiled from /usr/lib/python2.7/site-packages/numpy/linalg/linalg.pyc
dlopen("/usr/lib/python2.7/site-packages/numpy/linalg/lapack_lite.dll", 2);
Traceback (most recent call last):
  File "C:/Users/mack0242/Dropbox/PhD/scripts/cluster.py", line 5, in <module>
    from sklearn.cluster import DBSCAN
  File "/usr/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
    from .base import clone
  File "/usr/lib/python2.7/site-packages/sklearn/base.py", line 9, in <module>
    import numpy as np
  File "/usr/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/usr/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python2.7/site-packages/numpy/lib/__init__.py", line 18, in <module>
    from .polynomial import *
  File "/usr/lib/python2.7/site-packages/numpy/lib/polynomial.py", line 19, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "/usr/lib/python2.7/site-packages/numpy/linalg/__init__.py", line 51, in <module>
    from .linalg import *
  File "/usr/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 29, in <module>
    from numpy.linalg import lapack_lite, _umath_linalg
ImportError: No such file or directory

我已经仔细检查了文件:

/usr/lib/python2.7/site-packages/numpy/linalg/lapack_lite.dll

存在并且是64位。我已经在cygwin终端上成功安装了来自pip的numpy、scipy和sklearn。

此外,PyCharm表示没有名为sklearnmatplotlibnumpy的模块。

当我遇到类似的问题时(无法在Pycharm中导入numpy,而是在cygwin控制台上导入),结果发现cygwin使用了与Pycharm不同的解释器。

在PyCharm中,我从C:Program Filescygwinusrbinpython配置了解释器。相反,cygwin使用/bin/python。在PyCharm中单击File > Settings > Project: yourProjectName > Project Interpreter,单击"Add local",然后找到cygwin使用的解释器(在我的例子中是C:Program Filescygwinbinpython)。

然后通过View > Tools Windows > Python Console打开PyCharm中的Python控制台,并尝试导入语句。

相关内容

  • 没有找到相关文章