在利用python进行深度学习的过程中,需要用到cv2模块,但是无法直接import,查找资料后得知需要对opencv模块下的cv2.cpxx.xxxx.pyd文件进行操作才能解决问题
步骤如下:、
1、使用pip或者conda下载opencv模块
pip install opencv
conda install opencv
觉得太慢可以更改源
pip更改方式
在C盘的User文件夹中找到自己计算机用户名的文件夹,创建pip文件夹,创建一个txt,然后使用文本编辑软件输入:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
并改名为pip.ini即可,此处使用的是清华源
pip默认使用源:https://pypi.python.org/simple
国内可供使用的几个优质的源有:
豆瓣 https://pypi.douban.com/simple
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple
阿里云 https://mirrors.aliyun.com/pypi/simple
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple
conda更改方式
在Anaconda Prompt中输入:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
即可更改conda源,下载速度倍增
2、找到文件cv2.cpxx.xxxx.pyd的路径,并进行移动和重命名操作
这个是我电脑里安装opencv后该文件的路径
D:\Anaconda\envs\tf\Lib\site-packages\cv2.cp37-win_amd64.pyd
我使用的是conda的环境,其中的tf为环境名
找到该文件后,重命名为cv2.pyd,放入该环境下Lib的根目录下,即可import cv2