1.pip下载软件包
将pip所需安装包软件列表导出至文件
pip freeze bypy > requirement.txt
根据文件内容所需软件包列表,下载所需软件包至本地目录
pip download -d /python_packages -r requirement.txt
2.更换(Pypi)pip源到国内镜像
pip国内的一些镜像
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
提示:若担心安全问题请使用HTTPS加密源修改源方法:
2.1.修改源方法
临时使用
Linux Mac Windows 通用命令
可以在使用pip的时候在后面加上-i参数,指定pip源
pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple
永久修改
Linux:
修改 pip.conf 文件 (没有就创建一个)
$HOME/.config/pip/pip.conf
修改内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple12
Mac:
修改 pip.conf 文件
$HOME/Library/Application Support/pip/pip.conf
如果没有上面的目录,在如下目录创建 pip.conf
$HOME/.config/pip/pip.conf
修改内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple12
Windows:
修改 pip.conf 文件 (没有就创建一个)
%APPDATA%\pip\pip.ini
修改内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
2.2.修改文件后,执行命令发生错误
使用非HTTPS加密源(如豆瓣源),在执行命令发生错误,在命令最后加上–trusted-host pypi.douban.com
pip install django -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
或者在配置文件中修改内容如下
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
3.安装本地软件包
安装requirements.txt中需要的python包,仅仅使用本地wheels目录
pip install -r requirements.txt --no-index --find-links=./python_packages/
使用本地包更新pip、lxml软件包版本
pip install --upgrade pip lxml --no-index --find-links=./python_packages/
安装特定版本的软件包
pip install python-zunclient==1.1.0 --no-index --find-links=./python_packages/