当前位置 知且行 Python 正文 下一篇:

使用pyenv轻松管理python版本

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

    添加环境变量:

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

    重启shell

    1. exec "$SHELL"

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

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

    新建cache目录:

    1. mkdir ~/.pyenv/cache

    cache目录下执行:

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

    然后执行:

    1. $ pyenv install 3.6.6
    2. Installing Python-3.6.6...

    执行结束后查看版本:

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

    全局切换版本:

    1. $ pyenv global 3.6.6

    验证:

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

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

    转载必须注明出处:https://www.zhiqiexing.com/74.html

    关于我

    我希望能成为一个认真、有趣、创造更多价值的人
    关注微信
    微信扫一扫关注我

    微信扫一扫关注我

    返回顶部