python pip配置国内镜像源

1. 常用镜像源

Python中使用pip安装包,常用的国内镜像有:

  • 清华大学镜像:https://pypi.tuna.tsinghua.edu.cn/simple
  • 阿里云:http://mirrors.aliyun.com/pypi/simple/
  • 豆瓣:http://pypi.douban.com/simple/
  • 华中理工大学 :http://pypi.hustunique.com/simple
  • 山东理工大学 :http://pypi.sdutlinux.org/simple
  • 阿里云:http://mirrors.aliyun.com/pypi/simple/
  • 中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/

临时使用镜像进行pip安装:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas

# 如果上一个提示不受信任,就使用这个,此参数“--trusted-host”表示信任
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn

# 如果网络不好,出现超时的情况,可以加上超时时间配置,--default-timeout
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn --default-timeout=600

# 有的服务器上需要添加代理(--proxy)参数才能联网安装
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn --default-timeout=600 --proxy=http://用户名:密码@proxy.域名:8080 

但是最好直接在配置文件中配置镜像,永久性生效。

2. 镜像源永久生效

2.1 windows平台永久安装

  1. 进入相应目录下 C盘->Users/用户->xxx->新建pip文件夹
    在这里插入图片描述
  2. 进入pip文件夹,新建pip.ini文件
    在这里插入图片描述
  3. 打开pip.ini文件,并添加如下配置,并保存:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

在这里插入图片描述
保存之后,直接使用pip安装包,不需要带镜像,下载速度至少提升10倍以上

2.2 Linux平台永久安装

在这里插入图片描述

  1. home(上图示例是root用户)目录下,创建.pip文件夹
cd ~
mkdir .pip
  1. 进入.pip文件夹,并新建pip.conf文件
cd ~/.pip
touch pip.conf
  1. pip.conf文件中添加如下配置,并保存:
[global] 
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

3. pip文件添加多个国内镜像源

[global]
timeout=40
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
extra-index-url=
        http://mirrors.aliyun.com/pypi/simple/
        http://pypi.douban.com/simple
        http://pypi.mirrors.ustc.edu.cn/simple/

[install]
trusted-host=
        pypi.tuna.tsinghua.edu.cn
        mirrors.aliyun.com
        pypi.douban.com
        pypi.mirrors.ustc.edu.cn

4. pip常用命令

  • 格式化展示已安装包:pip freeze
  • 批量安装:pip install -r requirements.txt
  • 升级包:pip install --upgrade 要升级的包名
  • 卸载包:pip uninstall 包名
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值