最近使用yolov5做项目,但是在安装pycocotools和opencv的时候却遇到了麻烦,始终报错。尝试了网上的各种解决办法都无解,历时一下午终于解决了这个头疼的问题。
问题
首先建立了yolov5的虚拟环境,然后切换到yolov5环境下,根据官方源码的requirements.txt文件安装依赖关系。
(yolov5) C:\Research\landslide\code\yolov5\yolov5-master>pip install -r C:\Research\landslide\code\yolov5\yolov5-master\requirements.txt
一杯茶结束后,发现报错,然后 conda list列出所有包和requirements.txt中的要求对比,发现少了pycocotools和opencv-python两个包。然后再次执行下面的代码都报错。
pip install pycocotools
pip install opencv-python
分别报错信息如下:
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/pycocotools/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/pycocotools/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/pycocotools/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/pycocotools/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/pycocotools/
Could not fetch URL https://pypi.org/simple/pycocotools/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pycocotools/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))) - skipping
ERROR: Could not find a version that satisfies the requirement pycocotools
ERROR: No matching distribution found for pycocotools
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/opencv-python/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/opencv-python/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/opencv-python/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/opencv-python/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': /simple/opencv-python/
Could not fetch URL https://pypi.org/simple/opencv-python/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/opencv-python/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))) - skipping
ERROR: Could not find a version that satisfies the requirement opencv-python
ERROR: No matching distribution found for opencv-python
最后找到的解决办法就是,到对应的官网去下载.whl文件包,然后指定路径安装就可以
opencv的安装
下载安装包
到oencv官网下载对应的.whl文件(opencv官网下载地址)
根据自己的python和电脑操作系统版本下载对应的包,我下载的是:
opencv_python-4.4.0-cp38-cp38-win_amd64.whl
opencv_python-4.4.0:opencv版本号
cp38-cp38:环境中python的版本号
win_amd64:windows64位操作系统
放置到对应的环境中
将下载好的.whl放置到anaconda目录下的yolov5环境中的site-packages文件下下,比如我放置在
安装opencv
最后再次安装opencv
(yolov5) C:\Research\landslide\code\yolov5\yolov5-master>pip install C:\Users\40809\anaconda3\envs\yolov5\Lib\site-packages\opencv_python-4.4.0-cp38-cp38-win_amd64.whl
提示如下即为安装成功
Processing c:\users\40809\anaconda3\envs\yolov5\lib\site-packages\opencv_python-4.4.0-cp38-cp38-win_amd64.whl
Installing collected packages: opencv-python
Successfully installed opencv-python-4.4.0
安装pycocotools
安装方法和安装opencv一样,包下载地址(pycocotools下载地址)。
安装完成后运行 conda list即可看到已经全部安装成功。