pip常见用法汇总

1、pip安装

yum -y install epel-release && yum -y install python-pip

2、pip安装软件

(1)安装单个软件:pip install PackageName

(2)更新单个软件:pip install --upgrade PackageName

(3)卸载单个软件:pip uninstall PackageName

(4)查看已安装的软件:pip list或pip freeze –all或pip freeze(一般使用)

这三个的区别:pip freeze表示是后期安装的库,不包括安装python时自带的pip和setuptools。pip list和pip freeze –all表示所有的库,包括安装python时自带的pip和setuptools。

(5)列出所有过期的库;pip list --outdated

(6)pip批量更新(注意--upgrade后面的空格)

import pip

from subprocess import call

for dist in pip.get_installed_distributions():

    call("pip install –upgrade " + dist.project_name, shell=True)

(7)pip批量安装package

将需要安装的包保存在aa.txt中(pip freeze > aa.txt), cd到aa.txt所在目录,运行:pip install -r aa.txt

(8)pip批量卸载package

将需要卸载的包保存在aa.txt中,cd到aa.txt所在目录,运行:pip uninstall -r aa.txt

 

3、pip参数解释

pip --help

 Usage:  pip <command> [options]

 Commands:

  install             安装包.

  uninstall           卸载包.

  freeze             按着一定格式输出已安装包列表

  list                列出已安装包.

  show              显示包详细信息.

  search             搜索包,类似yum里的search.

  wheel             Build wheels from your requirements.

  help               当前帮助.

General Options:

  -h, --help            显示帮助.

  -v, --verbose          更多的输出,最多可以使用3次

  -V, --version          现实版本信息然后退出.

  -q, --quiet            最少的输出.

  --log-file <path>    覆盖的方式记录verbose错误日志,默认文件:/root/.pip/pip.log

  --log <path>          不覆盖记录verbose输出的日志.

  --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.

  --timeout <sec>         连接超时时间 (默认15秒).

  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.

  --cert <path>            证书.

猜你喜欢

转载自www.cnblogs.com/sanduzxcvbnm/p/9277146.html