版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jaket5219999/article/details/80815847
# pipenv 换源
python -c "s='https://mirrors.aliyun.com/pypi/simple';fn='Pipfile';pat=r'(\[\[source\]\]\s*url\s*=\s*\")(.+?)(\")';import re;fp=open(fn, 'r+');ss=fp.read();fp.seek(0);fp.truncate();fp.write(re.sub(pat, r'\1{}\3'.format(s), ss));fp.close();print('Done! Pipfile source switch to:\n'+s)"
cd 到Pipfile所在路径,在命令行中运行上面那个command,即可。
该command采用正则匹配Pipfile文件中``[[source]]\nurl = "xxx"``双引号里 的内容,并将其修改为变量s的内容。
方法二:采用系统自带的sed
sed -i 's|pypi.org|mirrors.aliyun.com/pypi|g' Pipfile
方法三:curl+python(支持python2和python3)
curl https://raw.githubusercontent.com/waketzheng/letstype/master/.switch_source_pipenv.py|python
-----------------------------------------------------------------------
换清华源:
python -c "s='https://pypi.tuna.tsinghua.edu.cn/simple';fn='Pipfile';pat=r'(\[\[source\]\]\s*url\s*=\s*\")(.+?)(\")';import re;fp=open(fn, 'r+');ss=fp.read();fp.seek(0);fp.truncate();fp.write(re.sub(pat, r'\1{}\3'.format(s), ss));fp.close();print('Done! Pipfile source switch to:\n'+s)"
豆瓣源:
python -c "s='https://pypi.douban.com/simple';fn='Pipfile';pat=r'(\[\[source\]\]\s*url\s*=\s*\")(.+?)(\")';import re;fp=open(fn, 'r+');ss=fp.read();fp.seek(0);fp.truncate();fp.write(re.sub(pat, r'\1{}\3'.format(s), ss));fp.close();print('Done! Pipfile source switch to:\n'+s)"
————————————————————————
换完源,安装package还是有点慢?看看这个pipenv install too slow
可以考虑用pipenv install --skip-lock xxx 来安装python包,然后另开一个终端来运行pipenv lock
¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥
# pip 换源(自动判断系统为windows或Linux,配置~/pip/pip.ini或~/.pip/pip.conf):
curl https://raw.githubusercontent.com/waketzheng/letstype/master/pip_conf.py|python
文件内容默认配置为阿里源:
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
也可以下载脚本到本地后运行python pip.conf -y -s douban配置为豆瓣源,或python pip.conf -y -s qinghua配置为清华源
Example:
wget https://raw.githubusercontent.com/waketzheng/letstype/master/pip_conf.py
python pip_conf.py -y -s douban