python3.7.1安装opencv4.0

本文详细介绍了如何下载并安装Python3.7.1,包括配置环境变量、选择安装选项等步骤。随后,指导读者如何通过pip安装NumPy和OpenCV库,以支持图像处理和计算机视觉应用。最后,提供了简单的代码示例来验证安装是否成功。

1、下载python3.7.1

(1)从以下地址下载:

https://www.python.org/downloads/release/python-371/

下载win64位的

(2)选择add to path,选择customize installation

(3)安装的内容都选上

(4)点击disable path length limit 比较好一些

(5)安装完毕

(6)编写一行代码看看正确否

2、安装NUMPY

(1)从以下地址下载

https://www.lfd.uci.edu/~gohlke/pythonlibs/#wordcloud

下载的版本为

(2)将下载的文件拷贝到D:\Program Files\Python37\Lib下面(你的安装目录下)

在windows文件夹的路径 中输入cmd 跳出对话框,输入pip install numpy-1.15.4+mkl-cp37-cp37m-win_amd64.whl

安装成功后提示

3、opencv4.0 python的下载地址

https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv

(1)下载如下版本

(2)

将下载的文件拷贝到D:\Program Files\Python37\Lib下面(你的安装目录下)

在windows文件夹的路径 中输入cmd 跳出对话框,输入pip install opencv_python-4.0.0+contrib-cp37-cp37m-win_amd64.whl

安装成功后提示:

(3)最后编写几行小代码测试下

 

import numpy as np

import cv2

image = cv2.imread("chen222.jpg")

cv2.imshow("Image",image)

cv2.waitKey(0)

D:\zanshi\1\pulse>conda env create -n pulse -f pulse.yml Channels: - pytorch - defaults - https://mirrors.bfsu.edu.cn/anaconda/cloud/pytorch - https://mirrors.ustc.edu.cn/anaconda/pkgs/free - https://mirrors.ustc.edu.cn/anaconda/pkgs/main - conda-forge Platform: win-64 Collecting package metadata (repodata.json): done Solving environment: failed Channels: - pytorch - defaults - https://mirrors.bfsu.edu.cn/anaconda/cloud/pytorch - https://mirrors.ustc.edu.cn/anaconda/pkgs/free - https://mirrors.ustc.edu.cn/anaconda/pkgs/main - conda-forge Platform: win-64 Collecting package metadata (repodata.json): done Solving environment: failed LibMambaUnsatisfiableError: Encountered problems while solving: - nothing provides requested mkl ==2019.4 233 - nothing provides requested jpeg ==9b he5867d9_2 - nothing provides requested torchvision 0.6.0** - nothing provides requested readline 8.0** - nothing provides requested ncurses 6.2** - nothing provides requested libgfortran 3.0.1** - nothing provides requested libedit 3.1.20181209** - nothing provides requested libcxx 10.0.0** - package tk-8.6.8-vc14_0 requires vc 14, but none of the providers can be installed Could not solve for environment specs The following packages are incompatible ├─ jpeg ==9b he5867d9_2 does not exist (perhaps a typo or a missing channel); ├─ libcxx 10.0.0** does not exist (perhaps a typo or a missing channel); ├─ libedit 3.1.20181209** does not exist (perhaps a typo or a missing channel); ├─ libgfortran 3.0.1** does not exist (perhaps a typo or a missing channel); ├─ mkl ==2019.4 233 does not exist (perhaps a typo or a missing channel); ├─ ncurses 6.2** does not exist (perhaps a typo or a missing channel); ├─ python 3.8.2** is requested and can be installed; ├─ pytorch 1.5.0** is installable and it requires │ └─ python >=3.7,<3.8.0a0 with the potential options │ ├─ python [3.7.0|3.7.1|...|3.7.7] conflicts with any installable versions previously reported; │ ├─ python [3.7.10|3.7.8|3.7.9] would require │ │ └─ sqlite >=3.33.0,<4.0a0 with the potential options │ │ ├─ sqlite 3.33.0, which can be installed; │ │ ├─ sqlite [3.34.0|3.35.0|...|3.35.5], which can be installed; │ │ ├─ sqlite [3.36.0|3.37.0|3.37.1|3.37.2], which can be installed; │ │ ├─ sqlite [3.38.0|3.38.2|...|3.39.2], which can be installed; │ │ ├─ sqlite [3.39.3|3.39.4], which can be installed; │ │ ├─ sqlite 3.40.0, which can be installed; │ │ ├─ sqlite [3.40.1|3.41.1|...|3.50.2], which can be installed; │ │ └─ sqlite 3.49.0 would require │ │ └─ libsqlite 3.49.0 h67fdade_0, which does not exist (perhaps a missing channel); │ ├─ python [3.7.10|3.7.11|3.7.12] would require │ │ └─ sqlite >=3.36.0,<4.0a0 with the potential options │ │ ├─ sqlite [3.36.0|3.37.0|3.37.1|3.37.2], which can be installed; │ │ ├─ sqlite [3.38.0|3.38.2|...|3.39.2], which can be installed; │ │ ├─ sqlite [3.39.3|3.39.4], which can be installed; │ │ ├─ sqlite 3.40.0, which can be installed; │ │ ├─ sqlite [3.40.1|3.41.1|...|3.50.2], which can be installed; │ │ └─ sqlite 3.49.0, which cannot be installed (as previously explained); │ ├─ python 3.7.13 would require │ │ └─ sqlite >=3.38.0,<4.0a0 with the potential options │ │ ├─ sqlite [3.38.0|3.38.2|...|3.39.2], which can be installed; │ │ ├─ sqlite [3.39.3|3.39.4], which can be installed; │ │ ├─ sqlite 3.40.0, which can be installed; │ │ ├─ sqlite [3.40.1|3.41.1|...|3.50.2], which can be installed; │ │ └─ sqlite 3.49.0, which cannot be installed (as previously explained); │ ├─ python [3.7.13|3.7.15] would require │ │ └─ sqlite >=3.39.3,<4.0a0 with the potential options │ │ ├─ sqlite [3.39.3|3.39.4], which can be installed; │ │ ├─ sqlite 3.40.0, which can be installed; │ │ ├─ sqlite [3.40.1|3.41.1|...|3.50.2], which can be installed; │ │ └─ sqlite 3.49.0, which cannot be installed (as previously explained); │ ├─ python 3.7.15 would require │ │ └─ sqlite >=3.40.0,<4.0a0 with the potential options │ │ ├─ sqlite 3.40.0, which can be installed; │ │ ├─ sqlite [3.40.1|3.41.1|...|3.50.2], which can be installed; │ │ └─ sqlite 3.49.0, which cannot be installed (as previously explained); │ ├─ python 3.7.16 would require │ │ └─ sqlite >=3.40.1,<4.0a0 with the potential options │ │ ├─ sqlite [3.40.1|3.41.1|...|3.50.2], which can be installed; │ │ └─ sqlite 3.49.0, which cannot be installed (as previously explained); │ ├─ python 3.7.10 would require │ │ └─ pypy3.7 7.3.5.* with the potential options │ │ ├─ pypy3.7 7.3.5 would require │ │ │ └─ tk >=8.6.11,<8.7.0a0 with the potential options │ │ │ ├─ tk [8.6.11|8.6.12|8.6.13], which can be installed; │ │ │ └─ tk 8.6.14 would require │ │ │ └─ zlib >=1.2.13,<1.3.0a0 , which can be installed; │ │ └─ pypy3.7 7.3.5 would require │ │ └─ tk >=8.6.10,<8.7.0a0 with the potential options │ │ ├─ tk 8.6.10, which can be installed; │ │ ├─ tk [8.6.11|8.6.12|8.6.13], which can be installed; │ │ └─ tk 8.6.14, which can be installed (as previously explained); │ ├─ python [3.7.10|3.7.5|3.7.9] would require │ │ └─ sqlite >=3.34.0,<4.0a0 with the potential options │ │ ├─ sqlite [3.34.0|3.35.0|...|3.35.5], which can be installed; │ │ ├─ sqlite [3.36.0|3.37.0|3.37.1|3.37.2], which can be installed; │ │ ├─ sqlite [3.38.0|3.38.2|...|3.39.2], which can be installed; │ │ ├─ sqlite [3.39.3|3.39.4], which can be installed; │ │ ├─ sqlite 3.40.0, which can be installed; │ │ ├─ sqlite [3.40.1|3.41.1|...|3.50.2], which can be installed; │ │ └─ sqlite 3.49.0, which cannot be installed (as previously explained); │ ├─ python 3.7.12 would require │ │ └─ pypy3.7 7.3.7.* , which requires │ │ └─ libzlib >=1.2.11,<2.0.0a0 with the potential options │ │ ├─ libzlib 1.2.11 would require │ │ │ └─ zlib 1.2.11 *_1012, which can be installed; │ │ ├─ libzlib 1.2.11 would require │ │ │ └─ zlib 1.2.11 *_1013, which can be installed; │ │ ├─ libzlib 1.2.11 would require │ │ │ └─ zlib 1.2.11 *_1014, which can be installed; │ │ ├─ libzlib 1.2.12 would require │ │ │ └─ zlib 1.2.12 *_0, which can be installed; │ │ ├─ libzlib 1.2.12 would require │ │ │ └─ zlib 1.2.12 *_1, which can be installed; │ │ ├─ libzlib 1.2.12 would require │ │ │ └─ zlib 1.2.12 *_2, which can be installed; │ │ ├─ libzlib 1.2.12 would require │ │ │ └─ zlib 1.2.12 *_3, which can be installed; │ │ ├─ libzlib 1.2.12 would require │ │ │ └─ zlib 1.2.12 *_4, which can be installed; │ │ ├─ libzlib 1.2.13 would require │ │ │ └─ zlib 1.2.13 *_4, which can be installed; │ │ ├─ libzlib 1.2.13 would require │ │ │ └─ zlib 1.2.13 *_6, which can be installed; │ │ ├─ libzlib 1.2.13 would require │ │ │ └─ zlib 1.2.13 *_5, which can be installed; │ │ ├─ libzlib 1.3 would require │ │ │ └─ zlib 1.3 *_0, which can be installed; │ │ ├─ libzlib 1.3.1 would require │ │ │ └─ zlib 1.3.1 *_1, which can be installed; │ │ ├─ libzlib 1.3.1 would require │ │ │ └─ zlib 1.3.1 *_2, which can be installed; │ │ └─ libzlib 1.3.1 would require │ │ └─ zlib 1.3.1 *_0, which can be installed; │ └─ python 3.7.8 would require │ └─ sqlite >=3.32.3,<4.0a0 with the potential options │ ├─ sqlite 3.32.3, which can be installed; │ ├─ sqlite 3.33.0, which can be installed; │ ├─ sqlite [3.34.0|3.35.0|...|3.35.5], which can be installed; │ ├─ sqlite [3.36.0|3.37.0|3.37.1|3.37.2], which can be installed; │ ├─ sqlite [3.38.0|3.38.2|...|3.39.2], which can be installed; │ ├─ sqlite [3.39.3|3.39.4], which can be installed; │ ├─ sqlite 3.40.0, which can be installed; │ ├─ sqlite [3.40.1|3.41.1|...|3.50.2], which can be installed; │ └─ sqlite 3.49.0, which cannot be installed (as previously explained); ├─ readline 8.0** does not exist (perhaps a typo or a missing channel); ├─ sqlite 3.31.1** is not installable because it conflicts with any installable versions previously reported; ├─ tk 8.6.8** is not installable because there are no viable options │ ├─ tk 8.6.8 conflicts with any installable versions previously reported; │ └─ tk 8.6.8 would require │ └─ vc 14 , which can be installed; ├─ torchvision 0.6.0** does not exist (perhaps a typo or a missing channel); └─ zlib 1.2.11** is not installable because there are no viable options ├─ zlib 1.2.11 would require │ └─ vc 10 , which conflicts with any installable versions previously reported; └─ zlib 1.2.11 conflicts with any installable versions previously reported. D:\zanshi\1\pulse>python run.py Traceback (most recent call last): File "D:\zanshi\1\pulse\run.py", line 1, in <module> from PULSE import PULSE File "D:\zanshi\1\pulse\PULSE.py", line 1, in <module> from stylegan import G_synthesis,G_mapping File "D:\zanshi\1\pulse\stylegan.py", line 3, in <module> import torch ModuleNotFoundError: No module named &#39;torch&#39;
06-30
<think>好的,我现在需要帮用户解决在Python安装OpenCV模块的问题。首先,我得回忆一下用户提供的引用内容。根据引用[2]和[3],安装OpenCV-Python库通常使用pip命令,比如pip install opencv-python。用户可能对Python模块安装不太熟悉,所以需要详细步骤。 接下来,我得考虑用户的环境。用户可能使用的是不同操作系统,比如Windows、macOS或者Linux。虽然引用里提到的是在Linux下查看版本,但安装步骤可能因系统而异。不过,使用pip通常是跨平台的,所以重点放在通用的方法上。 然后,用户可能遇到常见问题,比如pip版本过旧,或者安装后导入cv2时报错。需要提醒他们更新pip,并检查安装是否正确。引用[1]提到pkg-config检查版本,这可能是在Linux下验证安装的方法,但普通用户可能不需要这一步,可以简要提及。 还要注意Python版本,比如用户是否用Python3,因为引用[2]提到Python3.7.4。因此,安装命令可能需要用pip3而不是pip,特别是当系统同时安装Python2和3的时候。 此外,用户可能不知道安装完成后如何验证,所以需要给出简单的测试代码,比如导入cv2并打印版本。这能帮助他们确认安装成功。 最后,生成相关问题时要围绕常见问题,比如安装失败怎么办,其他版本安装,或者使用OpenCV的功能。确保问题对用户后续学习有帮助。</think>### 如何在Python安装OpenCV模块? #### 步骤说明 1. **安装前提** 确保已安装Python和包管理工具`pip`。可通过以下命令检查版本: ```bash python --version # 或 python3 --version pip --version # 或 pip3 --version ``` 如果未安装`pip`,需先通过系统包管理器或官方文档安装。 2. **使用pip安装OpenCV-Python** OpenCV的官方Python版本包为`opencv-python`,直接通过pip安装: ```bash pip install opencv-python # 若使用Python3,可能需要替换为pip3 ``` 此命令会安装主模块。如需额外功能(如非免费算法),可安装`opencv-contrib-python`[^3]: ```bash pip install opencv-contrib-python ``` 3. **验证安装** 安装完成后,在Python中导入并检查版本: ```python import cv2 print(cv2.__version__) # 输出应为4.x.x ``` 若报错`ModuleNotFoundError`,需检查Python环境路径或重新安装。 #### 常见问题解决 - **安装失败**:可能是网络问题或权限不足。可尝试: - 使用国内镜像源:`pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple` - 添加`--user`参数避免权限问题:`pip install --user opencv-python` - **版本兼容性**:若Python版本过旧(如低于3.6),需升级Python[^2]。 #### 代码示例(验证) ```python import cv2 # 读取图片并显示 img = cv2.imread("test.jpg") cv2.imshow("Image", img) cv2.waitKey(0) cv2.destroyAllWindows() ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值