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: