一、问题描述
pip install opencv-python==3.4.1.15,报错 raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python==3.4.1.15,依然报错
分析:问题出现在了没有关代理,关闭代理试试看就可以了
conda install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python==3.4.1.15报错
conda install opencv-python==3.4.1.15,依然报错
conda install opencv-python,依然报错
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python出现报错如下:
Building wheels for collected packages: opencv-python
Building wheel for opencv-python (PEP 517) ... error
ERROR: Failed building wheel for opencv-python
Failed to build opencv-python
ERROR: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly
pip install --upgrade pip setuptools wheel,出现报错ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。: 'd:\\users\\anaconda3\\envs\\pytorch\\scripts\\pip.exe'
Consider using the `--user` option or check the permissions.
分析:python -m ensurepip修复pip,再使用python -m pip install --upgrade pip升级pip
python -m ensurepip
python -m pip install --upgrade pip
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python依然报错
ERROR: Failed building wheel for opencv-python
Failed to build opencv-python
ERROR: Could not build wheels for opencv-python, which is required to install pyproject.toml-based projects
pip install opencv-python,还是依然报一样的错
分析:pip install opencv-python安装的是最新版本,python3.6版本不支持,所以找一个python3.6支持的版本即可,比如opencv-python版本4.3.0.38
pip install -i https://pypi.douban.com/simple/ pip install opencv-python==4.3.0.38
这次opencv成功安装了
WARNING: Ignoring invalid distribution -ip (d:\users\anaconda3\envs\pytorch\lib\site-packages)
WARNING: Ignoring invalid distribution -ip (d:\users\anaconda3\envs\pytorch\lib\site-packages)
这个可以找到指定文件夹里面删去以~开头文件夹即可
二、分析与总结
未关闭代理报错
关闭代理之后发现pip缺失报错还需要修复pip,修复之后重新升级pip
未指定版本导致安装的是最新版本,与python3.6不匹配也报错
最终指定opencv-python版本情况下安装成功
接着由于包重名还需要删去指定路径里面~开头文件夹