我是Python的初学者。当我想安装 NumPy 时,我没有工作,特别是当执行到“准备轮元数据”这一行时,出现错误:
C:\Users\dell>pip install numpy
Defaulting to user installation because normal site-packages is not writeable
Collecting numpy
Using cached numpy-1.19.2.zip (7.3 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... error
Run Code Online (Sandbox Code Playgroud)
ERROR: Command errored out with exit status 1: 'c:\program files\python39\python.exe' 'c:\program files\python39\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\dell\AppData\Local\Temp\tmphnzlje19' Check the logs for full command output.
Run Code Online (Sandbox Code Playgroud)
此pip install命令正在尝试从源代码构建 numpy。您可以看到这一点,因为.zip正在下载的是文件而不是轮.whl文件。该.zip文件包含源代码。NumPy 的大部分内容都是用 C 编写的,需要编译,但您的计算机很可能没有安装编译器。Wheel ( .whl) 文件不需要编译——它包含已经编译的代码,因此您不需要编译器。
编辑(2020 年 12 月 15 日):wheel 文件可用于版本 1.19.4,因此可以pip install numpy与 python 3.9 一起使用。
根据https://pypi.org/project/numpy/#files,还没有适用于 python 3.9 的wheel文件,因此您的选择是从源代码构建numpy,使用python 3.8,直到出现适用于python 3.9的numpy Wheel,或 use conda,它已经为 python 3.9 分发了 numpy。