我正在尝试安装适用于 python3.10 的 numpy(不在 venv 中)。我使用以下方法安装了 python 3.10
sudo apt install python3.10
pip 似乎没有安装,所以我安装了
jeremy@jeremy-Blade:/$ python3.10 -m pip install numpy
jeremy@jeremy-Blade:/$ wget https://bootstrap.pypa.io/get-pip.py
jeremy@jeremy-Blade:/$ python3.10 get-pip.py
jeremy@jeremy-Blade:/$ python3.10 -m pip --version
pip 21.3.1 from /home/jeremy/.local/lib/python3.10/site-packages/pip (python 3.10)
然后尝试
jeremy@jeremy-Blade:/$ python3.10 -m pip install numpy
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (1.17.4)
但是当我尝试导入 numpy 时:
Python 3.10.0 (default, Oct 4 2021, 22:09:55) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 17, in <module>
from . import multiarray
File "/usr/lib/python3/dist-packages/numpy/core/multiarray.py", line 14, in <module>
from . import overrides
File "/usr/lib/python3/dist-packages/numpy/core/overrides.py", line 7, 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 "/usr/lib/python3/dist-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 47, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.10 from "/usr/bin/python3.10",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.17.4" 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
...
Original error was: No module named 'numpy.core._multiarray_umath'
我的路径是
jeremy@jeremy-Blade:/$env|grep PATH
LD_LIBRARY_PATH=/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs
PATH=/home/jeremy/.local/bin:/usr/local/cuda-10.2/bin:/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
(因此未设置 PYTHONPATH - 如果我将其设置为 /usr/bin/python3.10,这似乎不会改变任何东西),并且按照错误消息中的建议,我似乎没有看到任何问题。 (我卸载并重新安装了 numpy for python3.10,问题没有变化)我的操作系统是 ubuntu 20.04。如果这是显而易见的或与 numpy 无关的,很抱歉。
答案1
看起来 numpy 的现有版本 (1.17) 可以与 python3.10 兼容,但实际上并非最低要求 (1.21)。升级即可解决问题:
jeremy@jeremy-Blade:~$ python3.10 -m pip install --user --upgrade numpy
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (1.17.4)
Collecting numpy
Using cached numpy-1.21.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.9 MB)
Installing collected packages: numpy
Successfully installed numpy-1.21.4
jeremy@jeremy-Blade:~$ python3.10
Python 3.10.0 (default, Oct 4 2021, 22:09:55) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>
答案2
对我来说这个有效:
python -m pip install numpy --no-binary=:all:
更多信息
- 关于--no-binary选项:https://pip.pypa.io/en/latest/cli/pip_install/#cmdoption-no-binary
- 构建轮子与下载轮子:https://realpython.com/python-wheels/