pip安装opencv时报错:“Could not install packages due to an OSError”【python】

pip安装opencv时报错:“Could not install packages due to an OSError”

今天在安装opencv时遇到报错:
“ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: ‘c:\users\vpu\.conda\envs\my_detector_env\lib\site-packages\numpy-2.0.2.dist-info\METADATA’”

(my_detector_env) PS D:\Fang\Tennis\my_detector> pip install opencv-python
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting opencv-python
Requirement already satisfied: numpy>=1.17.0 in c:\users\vpu\.conda\envs\my_detector_env\lib\site-packages (from opencv-python) (2.0.2)
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'c:\\users\\vpu\\.conda\\envs\\my_detector_env\\lib\\site-packages\\numpy-2.0.2.dist-info\\METADATA'

WARNING: No metadata found in c:\users\vpu\.conda\envs\my_detector_env\lib\site-packages
Found existing installation: numpy 2.0.2
error: uninstall-no-record-file

× Cannot uninstall numpy 2.0.2
╰─> The package's contents are unknown: no RECORD file was found for numpy.

hint: You might be able to recover from this via: pip install --force-reinstall --no-deps numpy==2.0.2

意思是pip找不到 numpy-2.0.2.dist-info 文件夹下的 “METADATA” ,所以产生了这个报错。
这种情况下,就算强制重新安装numpy:

pip install --force-reinstall --no-deps numpy==2.0.2

也无法解决问题:

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ea/2b/7fc9f4e7ae5b507c1a3a21f0f15ed03e794c1242ea8a242ac158beb56034/numpy-2.0.2-cp39-cp39-win_amd64.whl (15.9 MB)
Installing collected packages: numpy
  Attempting uninstall: numpy
    WARNING: No metadata found in c:\users\vpu\.conda\envs\my_detector_env\lib\site-packages
    Found existing installation: numpy 2.0.2
error: uninstall-no-record-file

× Cannot uninstall numpy 2.0.2
╰─> The package's contents are unknown: no RECORD file was found for numpy.

hint: You might be able to recover from this via: pip install --force-reinstall --no-deps numpy==2.0.2

这时我们打开Windows的文件资源管理器,导航到 site-packages 文件夹下(即报错里的目录):

c:\users\vpu\.conda\envs\my_detector_env\lib\site-packages\

在这里插入图片描述
找到这三个与 numpy 相关的文件夹,把它们删除。
然后再尝试安装 numpy:

pip install numpy

即可安装成功:

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting numpy
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ea/2b/7fc9f4e7ae5b507c1a3a21f0f15ed03e794c1242ea8a242ac158beb56034/numpy-2.0.2-cp39-cp39-win_amd64.whl (15.9 MB)
Installing collected packages: numpy
Successfully installed numpy-2.0.2
(my_detector_env) PS D:\Fang\Tennis\my_detector> pip install opencv-python
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting opencv-python
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ec/6c/fab8113424af5049f85717e8e527ca3773299a3c6b02506e66436e19874f/opencv_python-4.10.0.84-cp37-abi3-win_amd64.whl (38.8 MB)
Requirement already satisfied: numpy>=1.17.0 in c:\users\vpu\.conda\envs\my_detector_env\lib\site-packages (from opencv-python) (2.0.2)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.10.0.84
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值