目的:减少 pip相关的信息检索次数
开始做好运维这件事
2021-12-16
一、概述
pip, virtualenv, fabric通称为pythoner的三大神器。
pip 是 Python 的包安装程序。
其实,pip 就是 Python 标准库(The Python Standard Library)中的一个包,只是这个包比较特殊,
用它可以来管理 Python 标准库(The Python Standard Library)中其他的包。
pip 支持从 PyPI,版本控制,本地项目以及直接从分发文件进行安装。pip 是一个命令行程序。
#安装,centos 自带python2.7 ,可以加装pip
curl -O https://bootstrap.pypa.io/get-pip.py
#
curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
python get-pip.py -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
#pip 升级
python -m pip install -U --force-reinstall pip
二、常用指令
包查看地址:Search results · PyPI
(1)查看使用说明
pip+ 回车
(2)查看所有可用版本:pip3 install setuptools==122222,注意是"122222"
(3)查看已经安装版本:pip3 list
(4)安装示例
pip install virtualenv -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
(5)确保安装、部署和开发者之间的一致性
#导出包含了当前环境中所有包及 各自的版本的简单列表
pip freeze > requirements.txt
您可以使用 “pip list”在不产生requirements文件的情况下, 查看已安装包的列表。
pip install -r requirements.txt
三、离线安装
#借助 wheel, 很容易就可以实现.
#首先, 你的开发机器上要安装 wheel:
pip3 install wheel
#接下来, 下载依赖包的 wheel 文件:
pip wheel -r requirements.txt
#默认情况下, 上述命令会下载 requirements.txt 中每个包的 wheel 包到当前目录的 wheelhouse 文件夹, 包括依赖的依赖.
#现在你可以把这个 wheelhouse 文件夹打包到你的安装包中. 在你的安装脚本中执行:
pip install --use-wheel --no-index --find-links=wheelhouse -r requirements.txt
#就可以实现离线安装了. 当然, 还要考虑 pip 以及 wheel 自身的安装.
四、其他
1.设置源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
2. pip.conf
位置/root/.config/pip/pip.conf ;如果丢失,可以手工创建;
国外源:
--extra-index-url https://pypi.python.org/simple \
国内源如下
[global]
timeout = 6000
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com