Доступ к Numpy в оболочке MSYS2 (где MINGW64 работает нормально, Windows 10)? - PullRequest
0 голосов
/ 26 апреля 2019

У меня установлен MSYS2 на Windows 10, и в нем я установил numpy для Python3 через pacman:

$ pacman -Ss numpy | grep installed
mingw64/mingw-w64-x86_64-python3-numpy 1.16.2-1 [installed]

Если я запускаю оболочку MINGW64 bash, то импортирую numpy хорошо:

user@DESKTOP-XYXYXY MINGW64 /c/temp
$ python3 -c 'import numpy'

user@DESKTOP-XYXYXY MINGW64 /c/temp
$ 

Но, когда я делаю то же самое из оболочки MSYS2 bash, сначала я должен явно добавить «site-packages» в PYTHONPATH, чтобы найти numpyPython - и даже тогда что-то идет не так:

user@DESKTOP-XYXYXY MSYS /c/temp
$ python3 -c 'import numpy'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'

user@DESKTOP-XYXYXY MSYS /c/temp
$ PYTHONPATH='/mingw64/lib/python3.7/site-packages' python -c 'import numpy'
Traceback (most recent call last):
  File "/mingw64/lib/python3.7/site-packages/numpy/core/__init__.py", line 40, in <module>
    from . import multiarray
  File "/mingw64/lib/python3.7/site-packages/numpy/core/multiarray.py", line 12, in <module>
    from . import overrides
  File "/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 "<string>", line 1, in <module>
  File "/mingw64/lib/python3.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/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/python.exe),
     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'

Оказывается, это _multiarray_umath - это dll:

$ find / -name '*multiarray_umath*'
/mingw64/lib/python3.7/site-packages/numpy/core/_multiarray_umath-cpython-37m.dll

... поэтому я подумал, может быть, мне следуеттакже «взломать» $ PATH, но без игры в кости:

user@DESKTOP-XYXYXY MSYS /c/temp
$ PATH="$PATH:/mingw64/lib/python3.7/site-packages" PYTHONPATH='/mingw64/lib/python3.7/site-packages' python -c 'import numpy'
Traceback (most recent call last):
  File "/mingw64/lib/python3.7/site-packages/numpy/core/__init__.py", line 40, in <module>
    from . import multiarray
  File "/mingw64/lib/python3.7/site-packages/numpy/core/multiarray.py", line 12, in <module>
    from . import overrides
  File "/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 "<string>", line 1, in <module>
  File "/mingw64/lib/python3.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/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/python.exe),
     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'

Возможно ли каким-то образом выполнить настройку через переменные окружения, чтобы я мог использовать numpy в Python3, также в MSYS2 bash оболочка?

1 Ответ

0 голосов
/ 26 апреля 2019

Что ж, получается, что на самом деле есть два разных python3 с, используемых в MINGW64:

user@DESKTOP-XYXYXY MINGW64 /c/temp
$ ls -la `which python3`
-rwxr-xr-x 1 user None 99328 Apr 23 10:20 /mingw64/bin/python3

... против MSYS2 bash оболочки:

user@DESKTOP-XYXYXY MSYS /c/temp
$ ls -la `which python3`                                                       
-rwxr-xr-x 1 user None 9039 Apr 25 08:50 /usr/bin/python3

Итак, хитрость не в том, чтобы установить переменную окружения, как PYTHONPATH, а в том, чтобы вызвать правильный питон; с этим, теперь я получаю правильный ответ под MSYS2:

user@DESKTOP-XYXYXY MSYS /c/temp
$ /mingw64/bin/python3 -c 'import sys; print(sys.path); import numpy'
['', 'C:/msys64/mingw64/lib/python37.zip', 'C:/msys64/mingw64/lib/python3.7', 'C:/msys64/mingw64/bin', 'C:/msys64/mingw64/lib/python3.7/lib-dynload', 'C:/msys64/mingw64/lib/python3.7/site-packages']

user@DESKTOP-XYXYXY MSYS /c/temp
$ 

Возможно, вы даже сможете «обмануть» путь, чтобы получить такое поведение без установки явного абсолютного пути:

# (this shows still the "old" msys python3)
user@DESKTOP-XYXYXY MSYS /c/temp
$ PATH="/mingw64/bin:$PATH" ls -la `which python3`
-rwxr-xr-x 1 user None 9039 Apr 25 08:50 /usr/bin/python3

# (like this, with subshell, it seems to work)
user@DESKTOP-XYXYXY MSYS /c/temp
$ PATH="/mingw64/bin:$PATH" bash -c 'ls -la `which python3`'
-rwxr-xr-x 1 user None 99328 Apr 23 10:20 /mingw64/bin/python3

# (but can seemingly call python3 without subshell)
user@DESKTOP-XYXYXY MSYS /c/temp
$ PATH="/mingw64/bin:$PATH" python3 -c 'import sys; print(sys.path); import numpy'
['', 'C:/msys64/mingw64/lib/python37.zip', 'C:/msys64/mingw64/lib/python3.7', 'C:/msys64/mingw64/bin', 'C:/msys64/mingw64/lib/python3.7/lib-dynload', 'C:/msys64/mingw64/lib/python3.7/site-packages']

# (program exits without a problem)
...