代码改变世界

pip 用法

2022-05-09 16:58  brookin  阅读(46)  评论(0编辑  收藏  举报

安装包

pip install <package-name>==<version>

查看当前包版本状态

$ pip list --outdated
Package                  Version             Latest      Type
------------------------ ------------------- ----------- -----
absl-py                  0.12.0              1.0.0       wheel
aiohttp                  3.7.4               3.8.1       wheel
appnope                  0.1.2               0.1.3       wheel
argon2-cffi              20.1.0              21.3.0      wheel
async-timeout            3.0.1               4.0.2       wheel
attrs                    20.3.0              21.4.0      wheel
bcrypt                   3.2.0               3.2.2       wheel
beautifulsoup4           4.10.0              4.11.1      wheel

升级指定的包

-U, --upgrade Upgrade all specified packages to the newest depends on the upgrade-strategy used.

pip install <package_name> --upgrade
pip install <package_name> -U

示例

pip install --upgrade gensim

升级全部包

// 更新升级全部包
pip list --outdate > outdate.txt
awk '{print $1}' outdate.txt | while read line; do pip install --upgrade $line; done

// 强制升级指定包
pip install --ignore-installed PyYAML

// 安装或升级指定包到制定版本
pip install --upgrade pagekage_name==version

环境移植

$ pip freeze
agate==1.6.0
agate-dbf==0.2.0
agate-excel==0.2.1
agate-sql==0.5.2

dump配置到requirements.txt文件中

pip freeze > requirements.txt
pip install -r requirements.txt

腾讯云镜像源加速 pip

临时使用

pip install -i https://mirrors.cloud.tencent.com/pypi/simple numpy pandas

设为默认

升级 pip 到最新的版本 (>=10.0.0)

pip install pip -U
或
pip install -i https://mirrors.cloud.tencent.com/pypi/simple --upgrade pip

设置源地址

pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple
或
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple