我正在使用 CygwinPortable,我将 Cygwin 环境装进了一个 U 盘里。
其中,Python 版本为:
Python 3.9.16 (main, Mar 8 2023, 22:47:22)
[GCC 11.3.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
我尝试安装 NumPy 失败了,出现了如下报错:
ERROR: Could not build wheels for numpy, which is required to install pyproject.
toml-based projects
根据提示安装 pyproject
执行如下命令:
pip3 install pyproject
安装完之后还是报错。
参考这个问题的链接:error: pyproject.toml-based projects
执行如下安装命令:
pip3 install psutil
报错信息显示 psutil
不支持 Windows 版本。 (这里的报错信息我也没保留)
转而参考博文:cygwin64安装pip2安装numpy
根据指导转到:解决pip的ImportError: cannot import name 'PackageFinder' from 'pip._internal.index' (xxxx)
博文认为关键在于更换 pip 版本。
执行如下命令:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
输出如下:
~$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2518k 100 2518k 0 0 503k 0 0:00:05 0:00:05 --:--:-- 492k
~$ python get-pip.py
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting pip
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/08/e3/57d4c24a050aa0bcc
a46b2920bff40847db79535dc78141eb83581a52eb8/pip-23.1.2-py3-none-any.whl (2.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 221.3 kB/s eta 0:00:00
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 23.1.2
Uninstalling pip-23.1.2:
Successfully uninstalled pip-23.1.2
Successfully installed pip-23.1.2
执行完该命令后的报错信息我没能保留,大概的意思就是 NumPy 编译错误。
经过检查,发现可能的原因是在勾选安装工具的时候没有安装 python-devel 这个工具包。
在菜单中选择 Open Cygwin Setup
,选择安装 python39-devel
。
安装 NumPy 过程卡死。停滞在如下内容:
~$ pip3 install numpy
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting numpy
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/2c/d4/590ae7df5044465c
c9fa2db152ae12468694d62d952b1528ecff328ef7fc/numpy-1.24.3.tar.gz (10.9 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: numpy
Building wheel for numpy (pyproject.toml) ... -
末尾的字符 -
仍在旋转,形如:
-
-> \
->|
-> /
-> -
但停滞数分钟。
换用如下命令:
/ $ pip install numpy --no-cache-dir
终端输出如下,依旧缓慢。
/ $ pip install numpy --no-cache-dir
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting numpy
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2c/d4/590ae7df5044465cc
9fa2db152ae12468694d62d952b1528ecff328ef7fc/numpy-1.24.3.tar.gz (10.9 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.9/10.9 MB 2.7 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: numpy
Building wheel for numpy (pyproject.toml) ... \
末尾的字符 -
仍在旋转,形如:
-
-> \
->|
-> /
-> -
但每一次旋转都要停滞数分钟。
已经等了几个小时了,依然卡在这个地方。
建议手动下载numpy的源码包,然后解压后安装,这样子应该能看到过程中的日志
网络问题
可以用
pip3 install numpy scipy matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
试试
Could not build wheels for numpy, which is required to install pyproject这个错误,我看挺多人都遇到过,原因无法定位。你可以尝试安装时指定pip源安装:pip instal xx -i https://mirrors.aliyun.com/pypi/simple
如果不行,那就只能手动下载numpy的whl文件,然后再安装了。具体方法为:
先访问下载地址https://pypi.org/project/numpy/#files
找到对应的版本的whl文件进行下载,然后pip install whl文件路径
最后在pip install numpy
根据你提供的信息,可能是在 CygwinPortable 中安装 NumPy 的过程中出现了一些问题。以下是一些可能有用的步骤:
首先,确保你已经正确地安装了 CygwinPortable,并且已经安装了必要的软件包(例如Python3、pip等)。
然后,在CygwinPortable终端中,尝试使用以下命令来安装NumPy:
Copy
pip3 install numpy
如果这个命令卡在了编译NumPy的过程中,你可以尝试加上`--no-cache-dir`参数来禁用缓存,或者使用以下命令来指定NumPy的安装源:
pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/
Copy
这将使用清华大学的镜像站点来下载NumPy,可能会更快一些。
如果在安装NumPy时遇到了错误,你可以尝试检查错误信息以了解更多的细节。在CygwinPortable终端中,你可以使用以下命令来查看错误日志:
Copy
pip3 install numpy 2>&1 | tee pip.log
这将把错误日志输出到文件pip.log中,你可以打开这个文件来查看错误信息。
如果遇到了编译错误,可能是由于你缺少一些必要的依赖项。你可以尝试安装这些依赖项,例如:
Copy
apt-cyg install gcc-g++ make liblapack-devel libblas-devel
```
这将安装一些常见的数值计算库,可能有助于解决编译错误。