学习深度学习时,使用pytorch时遇到numpy报错问题
一、问题描述
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.1.1 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
- 翻译:
使用 NumPy 1.x 编译的模块无法在NumPy 2.1.1 的版本,因为它可能会崩溃。同时支持 1.x 和 2.x版本的 NumPy 中,模块必须使用 NumPy 2.0 进行编译。某些模块可能需要重新构建,例如使用 ‘pybind11>=2.12’ 。
如果您是该模块的用户,最简单的解决方案是降级到“numpy<2”或尝试升级受影响的模块。我们预计某些模块需要时间来支持 NumPy 2。
❗大致问题描述就是:
“numpy版本原因导致部分模块编译不通过,从而引起程序崩溃,需要替换numpy2.0以下的版本。”
二、解决办法
- 查询numpy版本后,发现是2.1.1,而python版本是3.11.9
经过网上搜索,发现numpy版本和python版本有对应关系
- 查询numpy官网对应版本
- 重新安装对应版本numpy
(1)删除原先版本
pip uninstall Numpy
提示删除成功,但是仍有部分文件需手动删除
(2)安装对应版本numpy 1.26
pip install numpy==1.26.0
conda list
小结
安装一些依赖包时,不能图省事,还得看清楚对应版本再安装