pip常用命令、配置pip源
构建在 setuptools 之上,替代 easy_install。
1、查找软件
pip search Package
2、安装软件
pip install Package
pip install -r requirements.txt
常用选项
-r, --requirement <file> Install from the given requirements file.
-U, --upgrade Upgrade all specified packages to the newest available version.
--no-cache-dir Disable the cache.
-i, --index-url <url> Base URL of the Python Package Index.
-q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
3、更新软件
pip install -U Package
4、卸载软件
pip uninstall Package
5、列出已安装软件
pip list
pip freeze
pip freeze -r requirements.txt
6、查看一个软件包安装了哪些文件
pip show -f Package
7、命令补全
pip completion --bash >>.bash_profile
8、升级所有包
for i in `pip3 list --outdated --trusted-host pypi.douban.com | tail -n +3 | awk '{print $1}'`; do pip3 install -U $i; done
9、修改pip安装源。在mac上需要自己创建.pip/目录和配置文件。
mkdir ~/.pip
vim ~/.pip/pip.conf
# 阿里源
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
# 豆瓣源
[global]
index-url = https://pypi.douban.com/simple
trusted-host = pypi.douban.com
# 清华大学
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
10、强制重装 pip 解决 Warning: pip is being invoked by an old script wrapper
python3 -m pip install --upgrade --force-reinstall pip
参考文档