python pyenv install

  • pyenv 安装依赖包

    1
    [root@dev ~]# yum -y install readline readline-devel readline-static openssl openssl-devel openssl-static sqlite-devel bzip2-devel bzip2-libs
  • pyenv 安装

    1
    2
    3
    [root@localhost ~]# git clone https://github.com/yyuu/pyenv.git ~/.pyenv
    or:
    [root@localhost ~]# git clone https://github.com/yyuu/pyenv.git /mnt/app/pyenv
  • pyenv 环境变量

    1
    2
    3
    4
    5
    6
    7
    8
    [root@localhost ~]# echo 'export PYENV_ROOT="$HOME/.pyenv"' | tee /etc/profile.d/pyenv.sh
    or:
    [root@localhost ~]# echo 'export PYENV_ROOT="/mnt/app/pyenv"' | tee /etc/profile.d/pyenv.sh

    [root@localhost ~]# echo 'export PATH="$PYENV_ROOT/bin:$PATH"' | tee -a /etc/profile.d/pyenv.sh
    [root@localhost ~]# echo 'eval "$(pyenv init -)"' | tee -a /etc/profile.d/pyenv.sh
    [root@localhost ~]# source /etc/profile
    [root@localhost ~]# exec $SHELL
  • pyenv-virtual 安装

    1
    [root@localhost ~]# git clone https://github.com/yyuu/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
  • pyenv-virtual 环境变量设置

    1
    2
    3
    [root@localhost ~]# echo 'eval "$(pyenv virtualenv-init -)"' | tee -a /etc/profile.d/pyenv.sh
    [root@localhost ~]# source /etc/profile
    [root@localhost ~]# exec $SHELL

  • pyenv 更新

    1
    2
    [root@localhost ~]# cd $(pyenv root)
    [root@localhost .pyenv]# git pull
  • pyenv 删除

    1
    2
    3
    4
    [root@localhost ~]# rm -rf $(pyenv root)
    [root@localhost ~]# rm -rf /etc/profile.d/pyenv.sh
    [root@localhost ~]# source /etc/profile
    [root@localhost ~]# exec $SHELL
  • pyenv 查看当前版本(系统版本)

    1
    2
    [root@localhost ~]# pyenv versions
    * system (set by /root/.pyenv/version)
  • pyenv 查看版本列表

    1
    [root@localhost ~]# pyenv install --list
  • pyenv 安装python

    1
    2
    3
    4
    5
    6
    [root@localhost ~]# pyenv install 2.7.13
    [root@localhost ~]# pyenv rehash

    or:
    [root@localhost ~]# mkdir -p ${PYENV_ROOT}/cache
    [root@localhost ~]# v=2.7.13;wget -P /usr/local/pyenv/cache/ http://mirrors.sohu.com/python/$v/Python-$v.tar.xz;python install $v
  • pyenv 设置全局版本

    1
    2
    3
    4
    5
    6
    [root@localhost ~]# pyenv global 2.7.13
    [root@localhost ~]# pyenv versions
    system
    * 2.7.13 (set by /root/.pyenv/version)
    [root@localhost ~]# python -V
    Python 2.7.13
  • pyenv 设置本地版本,优先级高于global

    1
    [root@localhost ~]# pyenv local 2.7.13
  • pyenv 设置shell版本,优先级高于local,global

    1
    2
    [root@localhost ~]# pyenv shell 2.7.13
    [root@localhost ~]# pyenv shell --unset 2.7.13
  • python 卸载python

    1
    2
    [root@localhost ~]# pyenv uninstall 2.7.13
    [root@localhost ~]# pyenv rehash

  • 创建虚拟环境

    1
    [root@localhost ~]# pyenv virtualenv 2.7.13 myenv
  • 查看当前的虚拟环境

    1
    2
    3
    [root@localhost ~]# pyenv virtualenvs
    2.7.13/envs/myenv (created from /root/.pyenv/versions/2.7.13)
    myenv (created from /root/.pyenv/versions/2.7.13)
  • 删除虚拟环境

    1
    [root@localhost ~]# pyenv uninstall myenv
  • 切换到虚拟环境

    1
    2
    3
    4
    5
    6
    7
    [root@localhost ~]# pyenv activate myenv
    pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
    (myenv) [root@localhost ~]#

    注意:
    export PYENV_VIRTUALENV_DISABLE_PROMPT=1 表示关闭(myenv)
    export PYENV_VIRTUALENV_DISABLE_PROMPT=$1 表示打开(myenv)
  • 退出虚拟环境

    1
    2
    (myenv) [root@localhost ~]# source deactivate
    pyenv-virtualenv: deactivate 2.7.13/envs/myenv