Bugfighter日记:python 库numpy2.x和opencv的不兼容(不要下载最新版本!!)

1.下载最新版本时要谨慎

2.看报错信息

3思路

报错信息a:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 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.

此报错信息表示opencv无法用2.x版本的numpy运行。而最新版本仅为2.0.0刚好不能用!!

于是我尝试用

pip install numpy==1000

这种不合法语句调出现有版本

继续尝试安装。可是安装进程又报错了。

 note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

<class 'numpy.distutils.system_info.atlas_info'>
        NOT AVAILABLE

      lapack_info:
      No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
      customize MSVCCompiler

发现锅主要在于distutils这个东西。

找文心一言:

numpy.distutils._msvccompiler 是 NumPy 包中用于与 Microsoft Visual C++ (MSVC) 编译器交互的模块。这个模块是 NumPy 的构建系统的一部分,用于在 Windows 平台上编译扩展模块,尤其是当 NumPy 需要与本地代码(如 C、C++ 或 Fortran 代码)交互时。

当你在 Windows 上安装或构建 NumPy(或许多其他需要编译的 Python 包)时,numpy.distutils._msvccompiler 会被用来检测、配置和使用 MSVC 编译器。这个模块会尝试自动找到系统上安装的 MSVC 编译器,并设置适当的编译选项。

然而,这个模块通常是 NumPy 内部使用的,并且对于大多数用户来说,不需要直接与其交互。如果你是一个包开发者,并且需要编译包含本地代码的 Python 扩展,那么你可能会间接地通过这个模块与 MSVC 编译器进行交互。

请注意,随着 NumPy 和其他 Python 包的更新,这个模块的具体实现和接口可能会发生变化。因此,如果你正在开发需要编译本地代码的 Python 包,并且需要直接与此模块交互,建议查阅最新的 NumPy 文档和源代码以获取最准确的信息。

另外,从 NumPy 1.19.0 版本开始,NumPy 提供了对 meson 和 ninja 的支持,作为替代 MSVC 的另一种构建系统选项。这可能会影响到 numpy.distutils._msvccompiler 的使用,但具体取决于你的构建环境和需求。锅又在最新版本上

numpy最新版本不仅使我无法使用opencv

还使我无法在原有库的基础上安装其他版本的numpy,必须消灭其存在。

解决方案

1.uninstall删除numpy2.0

2重要前提:pip没问题

  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误是由于模块在编译时使用了与当前numpy版本不兼容的API版本导致的。具体而言,模块编译时使用的API版本为0xf,而当前安装的numpy版本为0xe,所以无法导入"numpy.core.multiarray"模块。 解决这个问题的一个可能方法是升级numpy到与模块编译时使用的API版本兼容的版本。你可以尝试更新numpy到最新版本,或者根据模块的要求安装特定版本的numpy。另外,还可以尝试重新编译模块以适应当前的numpy版本。具体的步骤和方法可以根据你使用的模块和环境进行调整。如果问题仍然存在,我建议你查看模块的文档或者与模块的开发者联系,以获取更具体的解决方案。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [解决import tensorflow as tf 出错的原因](https://download.csdn.net/download/weixin_38571759/13737616)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [解决RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe](https://blog.csdn.net/weixin_51221144/article/details/128029715)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [解决OpenCVNumpy版本不匹配问题](https://blog.csdn.net/weixin_45845039/article/details/130300561)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值