ModuleNotFoundError:没有模块命名为...仅针对某些软件包

时间:2019-05-08 08:05:46

标签: python module package python-import

我正在Win 10下使用Portable Msys2。 我已经安装了python 3.7和2.7。

仅导入某些软件包时,我发现错误。 我想我需要找到正确的PYTHONPATH设置,但到目前为止我还没有找到。

所有这些都是我在导入numpy时收到的错误所引起的(如下所示)。 然后我发现了其他“相似”但不相等的错误,而且不确定它们是否具有相同的来源。

作为参考,

$ env | grep -i python
PYTHONSTARTUP=/home/user1/.pythonrc
PYTHONPATH=( I will list options I tried below )

我的.pythonrc列在底部。

与导入相关的目录对似乎是:

  1. usrusr_spC:\Users\user1\Documents\appls_mydocs\PortableApps\MSYS2Portable\App\msys32\usr\lib\python3.7\
    C:\Users\user1\Documents\appls_mydocs\PortableApps\MSYS2Portable\App\msys32\usr\lib\python3.7\site-packages

  2. mingw64mingw64_spC:\Users\user1\Documents\appls_mydocs\PortableApps\MSYS2Portable\App\msys32\mingw64\lib\python3.7\
    C:\Users\user1\Documents\appls_mydocs\PortableApps\MSYS2Portable\App\msys32\mingw64\lib\python3.7\site-packages

对于PYTHONPATH的每个选项,我尝试导入(也许盲目地)仅在一个或另一个目录对中存在的模块和软件包。

  1. 成对mingw64,而不成对usr
    msilibmingw64中唯一没有出现在usr中的软件包。 mingw64中没有usr中没有的模块。
    cairocoloramanumpy属于mingw64_sp中存在的许多软件包,而这些软件包不在usr_sp中。 pytestmingw64_sp中存在的一个模块,而不是usr_sp中存在的模块。

  2. 成对usr,而不成对mingw64
    usr中没有mingw64中没有的软件包。 usr中没有mingw64中没有的模块。
    pipusr_sp中唯一没有出现在mingw64_sp中的软件包。 magicusr_sp中唯一不在mingw64_sp中的模块。

我尝试的选项是:

  1. PYTHONPATH中没有任何内容。 以下结果( tl; dr )表明找到了usrusr_sp,而没有找到mingw64mingw64_sp


    tl;博士

    [~]$ unset PYTHONPATH
    [~]$ python3
    Python 3.7.2 (default, Dec 26 2018, 08:23:20)
    [GCC 7.4.0] on msys
    Type "help", "copyright", "credits" or "license" for more information.
    Reading /home/user1/.pythonrc
    readline is in /usr/lib/python3.7/lib-dynload/readline.cpython-37m.dll
    >>> import sys
    >>> sys.path
    ['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/lib/python3.7/site-packages']
    >>> import datetime
    >>> import json
    >>> import msilib
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'msilib'
    >>> import cairo
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'cairo'
    >>> import colorama
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'colorama'
    >>> import pip
    >>> import pytest
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'pytest'
    >>> import magic
    >>> exit()
    

  2. PYTHONPATH,其中添加了mingw64对。 下面的结果( tl; dr )建议同时找到两个对(usrusr_sp)和({{11}},mingw64)。 但是仍然只缺少某些软件包(在这种情况下为mingw64_spmsilibcairo),而对于其他软件包,配置就足够了(在numpy)。 此外,现在colorama的阴影mingw64中有一些东西(请参见usr)。


    tld; dr

    import magic

我的[~]$ env | grep -i python PYTHONSTARTUP=/home/user1/.pythonrc PYTHONPATH=/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7:/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/site-packages [~]$ python3 Python 3.7.2 (default, Dec 26 2018, 08:23:20) [GCC 7.4.0] on msys Type "help", "copyright", "credits" or "license" for more information. Reading /home/user1/.pythonrc readline is in /usr/lib/python3.7/lib-dynload/readline.cpython-37m.dll >>> import sys >>> sys.path ['', '/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7', '/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/site-packages', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/lib/python3.7/site-packages'] >>> import datetime >>> import json >>> import msilib Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/msilib/__init__.py", line 3, in <module> from _msi import * ModuleNotFoundError: No module named '_msi' >>> import cairo Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/site-packages/cairo/__init__.py", line 1, in <module> from ._cairo import * # noqa: F401,F403 ModuleNotFoundError: No module named 'cairo._cairo' >>> import colorama >>> import numpy <----------------------- This sparked the question Traceback (most recent call last): File "/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/site-packages/numpy/core/__init__.py", line 40, in <module> from . import multiarray File "/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/site-packages/numpy/core/multiarray.py", line 12, in <module> from . import overrides File "/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/site-packages/numpy/core/overrides.py", line 6, in <module> from numpy.core._multiarray_umath import ( ModuleNotFoundError: No module named 'numpy.core._multiarray_umath' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/site-packages/numpy/__init__.py", line 142, in <module> from . import core File "/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/site-packages/numpy/core/__init__.py", line 71, in <module> raise ImportError(msg) ImportError: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. Here is how to proceed: - If you're working with a numpy git repository, try `git clean -xdf` (removes all files not under version control) and rebuild numpy. - If you are simply trying to use the numpy version that you have installed: your installation is broken - please reinstall numpy. - If you have already reinstalled and that did not fix the problem, then: 1. Check that you are using the Python you expect (you're using /usr/bin/python3), and that you have no directories in your PATH or PYTHONPATH that can interfere with the Python and numpy versions you're trying to use. 2. If (1) looks fine, you can open a new issue at https://github.com/numpy/numpy/issues. Please include details on: - how you installed Python - how you installed numpy - your operating system - whether or not you have multiple versions of Python installed - if you built from source, your compiler versions and ideally a build log Note: this error has many possible causes, so please don't comment on an existing issue about this - open a new one instead. Original error was: No module named 'numpy.core._multiarray_umath' >>> import pip >>> import pytest >>> import magic Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.7/site-packages/magic.py", line 61, in <module> _open = _libraries['magic'].magic_open File "/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/ctypes/__init__.py", line 369, in __getattr__ func = self.__getitem__(name) File "/c/Users/ry16205/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.7/ctypes/__init__.py", line 374, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: function 'magic_open' not found

.pythonrc

0 个答案:

没有答案