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