本文介绍了Python:从 cygwin 运行有效,而从 PyCharm 运行无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I can successfully run a python script that uses

from sklearn.cluster import DBSCAN

来自 64 位 cygwin 终端提示,它使用 64 位构建的 python 2.7.

from the 64 bit cygwin terminal prompt which uses a 64bit build of python 2.7.

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

When I run the same from both 64 bit and 32 bit pycharm with -vv interpreter options, I get (the first 2 lines are the verbose output):

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

我已经仔细检查了文件:

I have double checked and the file:

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

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

exists and is 64 bits. I have successfully installed numpy,scipy and sklearn from pip on the cygwin terminal.

此外,PyCharm 说没有名为 sklearnmatplotlibnumpy 的模块.

Additionally, PyCharm says there are no modules named sklearn, matplotlib and numpy.

推荐答案

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

When I had a similar problem (couldn't import numpy in Pycharm but on cygwin console), it turned out that cygwin was using a different interpreter as PyCharm.

在 PyCharm 中,我从 C:Program Filescygwinusrinpython 配置了解释器.相比之下,cygwin 使用的是 /bin/python.在 PyCharm 中单击 File >设置 >项目:您的项目名称 >Project Interpreter,点击Add local",找到cygwin使用的解释器(我这里是C:Program Filescygwininpython).

In PyCharm I had configured the interpreter from C:Program Filescygwinusrinpython. In contrast, cygwin was using /bin/python. In PyCharm click File > Settings > Project: yourProjectName > Project Interpreter, click on "Add local" and find the interpreter used by cygwin (in my case C:Program Filescygwininpython).

然后在 PyCharm 中通过 View > 打开 Python Console工具窗口 >Python 控制台 并尝试您的导入语句.

Then open the Python Console in PyCharm via View > Tools Windows > Python Console and try your import statement.

这篇关于Python:从 cygwin 运行有效,而从 PyCharm 运行无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:49