python中提高pip install速度

发布时间:2020-09-23 21:56:11 作者:大眼睛编程
来源:脚本之家 阅读:135

pip install命令默认是用的是python官方源,由于一些客观原因,连接速度很慢,甚至超时中断,到时很多模块安装不上,甚是苦恼!

怎么办?

使用国内镜像源,将以下命令完成拷贝出来,粘贴至记事本中,保存为bat文件,双击执行该批处理文件。

@echo off

rem 声明采用UTF-8编码chcp 65001

echo \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

echo 自动设置pip安装配置文件

echo \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

set pipFolder=\\pip\\

if exist %userprofile%%pipFolder% (

echo 目录%userprofile%%pipFolder%已存在无需创建

) else (

echo 创建%userprofile%%pipFolder%

md %userprofile%%PiPFolder%

)

cd %userprofile%%pipFolder%

echo \[global\]>pip.ini

(

echo timeout=60

echo index-url=http://pypi.douban.com/simple

echo extra-index-url=https://pypi.tuna.tsinghua.edu.cn/simple/

echo \[install\]

echo trusted-host=pypi.douban.com

echo pypi.tuna.tsinghua.edu.cn

echo timeout = 10

)>>pip.ini

wmic ENVIRONMENT where "name='path' and username='<system>'"

set VariableValue="%path%;%userprofile%%pipFolder%pip.ini"

然后再试试pip install命令,绝对飞一般的感觉。

另外给大家一些常用的pip国内源:

阿里云 https://mirrors.aliyun.com/pypi/simple/ 
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 
豆瓣(douban) https://pypi.douban.com/simple/ 
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 
中国科学技术大学 https://pypi.mirrors.ustc.edu.cn/simple/

使用方法

临时生效
使用时加上参数 -i

如:

pip install matplotlib -i https://mirrors.aliyun.com/pypi/simple/

永久生效

1.Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)

内容如下:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
 
[install]
trusted-host=mirrors.aliyun.com

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

推荐阅读:
  1. 提高pip install的下载速度
  2. Python中pip如何安装与使用

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

pip下载速度 加快pip速度 inst

上一篇:一道经典的Java面试题:equals ,== 和hashcode()的区别

下一篇:易语言显示所选择文件完整路径的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》