您的位置 首页 Python

使用pyenv轻松管理python版本

pyenv的github仓库下载源码包:$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv

添加环境变量:

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc

重启shell

exec "$SHELL"

由于众所周知的原因,直接连接外网下载安装包会慢到让人怀疑人生,只能另辟蹊径:

根据你要下载的版本拼接url,以3.6.6为例:https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz

新建cache目录:

mkdir ~/.pyenv/cache

cache目录下执行:

$ wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
--2019-01-24 14:29:46--  https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
Resolving www.python.org (www.python.org)... 151.101.108.223, 2a04:4e42:1a::223
Connecting to www.python.org (www.python.org)|151.101.108.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17156744 (16M) [application/octet-stream]
Saving to: ‘Python-3.6.6.tar.xz’

然后执行:

$ pyenv install 3.6.6
Installing Python-3.6.6...

执行结束后查看版本:

$ pyenv versions
* system (set by /home/airmb2019Usual/.pyenv/version)
  3.6.6

全局切换版本:

$ pyenv global 3.6.6

验证:

$ python
Python 3.6.6 (default, Jan 24 2019, 14:31:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

如果不生效,重新建立ssh连接再查看

本文由钟森龙创作,转载请注明出处:http://zhiqiexing.com/74.html
关注微信
微信扫码关注

微信扫一扫关注我

返回顶部