Python源码安装
- 下载
$ wget https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tgz
- 编译
$ tar -xzvf Python-3.6.10.tgz $ cd Python-3.6.10 $ ./configure --prefix=/usr/local $ make
- 安装
$ sudo make install
Python版本OpenCV的安装与卸载
- 安装指定版本OpenCV
如果出现错误提示,指定的版本未找到,则从提示信息中找到可用的版本,将“==”后面的版本号修改为可用的版本号。$ pip3 install opencv_python==4.1.0.25
- 卸载
- Linux
$ sudo pip3 uninstall opencv-python
- Windows
以管理员身份运行cmd
$ pip3 uninstall opencv-python
- 查看opencv版本
import cv2 cv2.__version__
离线安装模块
- 下载离线安装文件
pip freeze > requirements.txt pip download -r requirements.txt -d ./packages
- 安装
将下载的离线安装文件拷至要安装的计算机中,执行以下命令安装:pip install --no-index --find-links=d:\software\packages -r requirements.txt
离线安装pip和setuptools
- python
- 下载安装包
https://pypi.org/project/pip/#files - 安装
其中,pip-20.0.2-py2.py3-none-any.whl为pip安装包,不同版本其文件名不同。python -m pip install --upgrade pip-20.0.2-py2.py3-none-any.whl
- 下载安装包
- setuptools
- 下载安装包
https://pypi.org/project/setuptools/ - 安装
其中,setuptools-46.1.3.whl为安装包文件名,不同版本其文件名中的版本号也不同。pip install setuptools-46.1.3.whl
- 查看版本号
通过以下命令可查看setuptools的版本号。easy_install --version
- 下载安装包
修改下载源为国内源
- Windows
- 在User的用户名目录下创建pip目录,如:
C:\Users\Username\pip
- 在该目录下新建文件
pip.ini
,并在该文件中添加以下内容[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple
- 在User的用户名目录下创建pip目录,如:
- Linux
- 编辑
~/.pip/pip.conf
sudo vim ~/.pip/pip.conf
- 在pip.conf中添加
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn
- 保存并退出
- 编辑
问题及解决
- 问题:安装时出现错误提示
Could not find a version that satisfies the requirement torch==1.0.1
。
解决方法:pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp36-cp36m-win_amd64.whl
- 问题:使用pip安装模块时出现错误提示
could not find a version that satifies the requirement "setuptools"
,或No matching distribution found for setuptools>= 38.2.5
,或Could not find a version that satisfies the requirement wheel (from versions: ) No matching distribution found for wheel
。
解决方法:有两种解决方法:- 下载安装相应版本的setuptools或wheel,然后将其拷到要安装的模块所在目录,再执行批量安装。
- 模块所在的目录缺少模块文件,可使用
pip download
根据列表文件重新下载模块。