无法在cygwin中加载python模块

时间:2018-11-13 21:29:50

标签: python cygwin

我已经启动了cygwin并在Windows中运行,除了加载python模块外,其他一切似乎都工作正常。

>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/cygdrive/c/Users/mkupfer/appdata/local/programs/python/python36-32/lib/site-packages/requests/__init__.py", line 44, in <module>
    import chardet
ModuleNotFoundError: No module named 'chardet'

然后这是我为numpy遇到的另一个错误,看起来有些不同。

    >>> import numpy
Traceback (most recent call last):
  File "/cygdrive/c/Users/mkupfer/appdata/local/programs/python/python36-32/lib/site-packages/numpy/core/__init__.py", line 16, in <module>
    from . import multiarray
ImportError: cannot import name 'multiarray'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/cygdrive/c/Users/mkupfer/appdata/local/programs/python/python36-32/lib/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/cygdrive/c/Users/mkupfer/appdata/local/programs/python/python36-32/lib/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/cygdrive/c/Users/mkupfer/appdata/local/programs/python/python36-32/lib/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/cygdrive/c/Users/mkupfer/appdata/local/programs/python/python36-32/lib/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/cygdrive/c/Users/mkupfer/appdata/local/programs/python/python36-32/lib/site-packages/numpy/core/__init__.py", line 26, in <module>
    raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: cannot import name 'multiarray'

我最初以为这与我的sys.path有关?但是我已将以下内容添加到我的.bashrc文件中,但仍然存在上述问题:

PYTHONPATH="$HOME/appdata/local/programs/python/python36-32/lib/site-packages"
PYTHONPATH="${PYTHONPATH}:$HOME/appdata/local/programs/python/python36-32/lib"
export PYTHONPATH

我在这里尝试了另一个问题的解决方案:https://stackoverflow.com/a/32027563/1656488,但这仍然无法解决任何问题。实际上,它在我的Windows用户目录下安装了pip3,而不是在cygwin中。

1 个答案:

答案 0 :(得分:0)

我已按照此answer中的步骤解决了自己的问题。感谢@ not2qubit的雄辩解决方案。请点击链接,以便他们可以要求此答案提供信用。