pyenv 一次性换源

1,011 阅读1分钟

没找到pyenv永久换源的方法,自己写个简单的脚本。
~/目录下新建一个.py-installer.sh的隐藏文件

v=$1;
wget https://npm.taobao.org/mirrors/python/${v}/Python-${v}.tar.xz -P ~/.pyenv/cache/;
pyenv install ${v}
rm -rf ~/.pyenv/cache/Python-${v}.tar.xz

执行一下

chmod u+x ~/.py-installer.sh

否则可能没有权限 试一下

➜  ~ ./.py-installer.sh 3.8.3
--2021-01-24 04:46:00--  https://npm.taobao.org/mirrors/python/3.8.3/Python-3.8.3.tar.xz
Resolving npm.taobao.org (npm.taobao.org)... 114.55.80.225
Connecting to npm.taobao.org (npm.taobao.org)|114.55.80.225|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cdn.npm.taobao.org/dist/python/3.8.3/Python-3.8.3.tar.xz [following]
--2021-01-24 04:46:00--  https://cdn.npm.taobao.org/dist/python/3.8.3/Python-3.8.3.tar.xz
Resolving cdn.npm.taobao.org (cdn.npm.taobao.org)... 223.111.29.244, 36.156.125.240, 36.156.78.242, ...
Connecting to cdn.npm.taobao.org (cdn.npm.taobao.org)|223.111.29.244|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17912964 (17M) [application/x-xz]
Saving to: ‘/home/pi/.pyenv/cache/Python-3.8.3.tar.xz’

Python-3.8.3.tar.xz                                                 100%[===================================================================================================================================================================>]  17.08M  4.98MB/s    in 3.4s

2021-01-24 04:46:04 (4.98 MB/s) - ‘/home/pi/.pyenv/cache/Python-3.8.3.tar.xz’ saved [17912964/17912964]

Installing Python-3.8.3...
Installed Python-3.8.3 to /home/pi/.pyenv/versions/3.8.3
➜  ~ pyenv versions
* system (set by /home/pi/.pyenv/version)
  3.8.3

已经安装成功了,接下来把命令添加到.zshrc

alias install-py='~/.py-installer.sh'

刷新一下source ~/.zshrc

➜  ~ install-py 3.8.3
--2021-01-24 04:58:12--  https://npm.taobao.org/mirrors/python/3.8.3/Python-3.8.3.tar.xz
Resolving npm.taobao.org (npm.taobao.org)... 114.55.80.225
Connecting to npm.taobao.org (npm.taobao.org)|114.55.80.225|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cdn.npm.taobao.org/dist/python/3.8.3/Python-3.8.3.tar.xz [following]
--2021-01-24 04:58:12--  https://cdn.npm.taobao.org/dist/python/3.8.3/Python-3.8.3.tar.xz
Resolving cdn.npm.taobao.org (cdn.npm.taobao.org)... 183.213.21.213, 112.25.43.107, 223.111.123.167, ...
Connecting to cdn.npm.taobao.org (cdn.npm.taobao.org)|183.213.21.213|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17912964 (17M) [application/x-xz]
Saving to: ‘/home/pi/.pyenv/cache/Python-3.8.3.tar.xz.3’

Python-3.8.3.tar.xz.3                                               100%[===================================================================================================================================================================>]  17.08M  12.9MB/s    in 1.3s

2021-01-24 04:58:13 (12.9 MB/s) - ‘/home/pi/.pyenv/cache/Python-3.8.3.tar.xz.3’ saved [17912964/17912964]

pyenv: /home/pi/.pyenv/versions/3.8.3 already exists
continue with installation? (y/N)