在pycharm中升级pip失败和pip安装pytorch torchvision opencv

pytorch官网:
https://pytorch.org/get-started/locally/

查看版本:

pip --version
pip 20.2.3 from c:\users\14172\pycharmprojects\pythonproject3\venv\lib\site-packages\pip (python 3.9)
python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

第一次用的这个命令:
python -m pip install–upgrade pip -i
显然无法成功。。。。
在这里插入图片描述

然后这条命令试用了很多次:

python -m pip install -U --force-reinstall pip

报错:
ERROR: Exception:
Traceback (most recent call last):
在这里插入图片描述
在这里插入图片描述

然后一同学说用镜像安装。。于是输入:

python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple

然后成功了。
在这里插入图片描述

之后安装pytorch和torchvision的命令:

pip install torchvision=0.8.2 torchaudio=0.7.2 -f https://download.pytorch.org/whl/torch_stable.h
tml

报错:
在这里插入图片描述

RROR: Exception:
Traceback (most recent call last):
File “c:\users\14172\pycharmprojects\pythonproject3\venv\lib\site-packages\pip_vendor\resolvelib\resolvers.py”, line 171, in _merge_into_criterion
crit = self.state.criteria[name]
KeyError: ‘pillow’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “c:\users\14172\pycharmprojects\pythonproject3\venv\lib\site-packages\pip_vendor\urllib3\response.py”, line 438, in _error_catcher
yield
然后用命令:

pip install torchvision

继续报错:(试了三四次
在这里插入图片描述
然后去官网搜指令
输入:

pip install torchvision0.8.2+cpu torchaudio=0.7.2 -f https://download.pytorch.org/whl/torch_stable
.html

仍然不行:
在这里插入图片描述

然后去搜镜像,输入:

python -m pip install --upgrade torch torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple

成功了。结果:
在这里插入图片描述
然后安装opencv:

pip3 install opencv-contrib-python -i https://pypi.tuna.tsinghua.edu.cn/simple

在这里插入图片描述

简单测试opencv:
代码:

import cv2 as cv


if __name__ == '__main__':
    src = cv.imread("C:/Users/14172/Pictures/pp.png")

    cv.namedWindow("图片", cv.WINDOW_AUTOSIZE)
   
    cv.imshow("picture", src)
    ###显示图片
    cv.waitKey(0)
    ###等待下一步指令
    cv.destroyAllWindows()

图片是自己c盘下面存的一张图片,其中路径把\换成/
结果:
在这里插入图片描述

安装opencv-python:
输入

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python

install sucessfully:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_41358574/article/details/113093566
今日推荐