pip的使用

pip是python的包管理工具,pip和pip3版本不同,都位于Scripts\目录下:
如果只安装了Python2,则只能使用pip。
如果只安装了Python3,则可以使用pip和pip3,二者是等价的。
如果同时安装了Python2和Python3,则pip默认给Python2用,pip3指定给Python3用。
一. pip用法

用法:
pip [options]

命令:
install 安装指定包.
download 下载指定包.
uninstall 卸载指定包.
freeze 输出已经安装的某个包的依赖信息.
list 列出所有已经安装的包.
show 显示指定的某个已经安装的包的详细信息.
check 检查已经安装的某个包是否有依赖问题.
search 搜索符合条件的包
wheel 安装whl格式的wheel包.
hash 计算指定包的hash值.
help 显示帮助信息.

General Options:
-h, --help Show help.
–isolated 在一个单独的环境中运行pip,忽略环境变量和用户配置.
-v, --verbose 显示更多的输出信息.
-V, --version 显示pip版本.
-q, --quiet 显示更少的输出,只显示WARNING,ERROR, and CRITICALG级别的日志.
–proxy 指定代理,代理格式:
[user:passwd@]proxy.server:port.
–retries 每个连接的最大重试次数,默认5次.
–timeout 设置socket的超时时间,默认15秒.
–exists-action Default action when a path already exists:
(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
–trusted-host Mark this host as trusted, even though it does
not have valid or any HTTPS.
–cert Path to alternate CA bundle.
–client-cert Path to SSL client certificate, a single file
containing the private key and the certificate
in PEM format.
–cache-dir

Store the cache data in .
–no-cache-dir Disable the cache.
–disable-pip-version-check
Don’t periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with --no-index.

二. 使用指定镜像

我们在使用pip在线安装时,经常遇到网络不稳定,或者因为某种原因导致的网络无法访问,这时我们可以通过指定特定的源镜像来安装(如国内的源):
如果想手动指定源,可以使用pip -i来指定源,比如用豆瓣的源来安装web.py框架:

pip install web.py -i https://pypi.douban.com/simple

1

也可以将源写进配置文件,这样就不用每次都输入命令了。打开配置文件%APPDATA%\pip\pip.ini(如果没有,可以手动新建一个),修改内容:

[global]
index-url = https://pypi.douban.com/simple

作者:china_jeffery
来源:CSDN
原文:https://blog.csdn.net/china_jeffery/article/details/79255843
版权声明:本文为博主原创文章,转载请附上博文链接!

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/

修改源方法:

临时使用:
可以在使用pip的时候在后面加上-i参数,指定pip源
eg: pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple

永久修改:
linux:
修改 ~/.pip/pip.conf (没有就创建一个), 内容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

windows:
直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值