在同一台机器上使用不同的python版本

###方法一

  • 使用pyenv

    1
    2
    3
    4
    5
    
    git clone git://github.com/yyuu/pyenv.git ~/.pyenv
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(pyenv init -)"' >> ~/.bashrc
    exec $SHELL -l

安装python3.6

1
2
3
4
5
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev

pyenv install 3.6.4

###方法二

sudo apt-get install python3

安装pip3:

1
2
3
4
:::text
cd /tmp
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo python3 get-pip.py

##参考资料 * Python多版本共存之pyenv * how-to-use-pip-with-python-3-x-alongside-python-2-x