pyenv is a simple python version management tool. pyenv lets you easily switch between multiple versions of Python.
Vitualenv is a tool to create isolated Python environments.
1. Install curl and git
sudo apt-get install curl git-core
2. Install pyenv
curl -L https://raw.github.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
pyenv will be installed in ~/.pyenv
3. Add codes to ~/.bashrc
export PYENV_ROOT="${HOME}/.pyenv" if [ -d "${PYENV_ROOT}" ]; then export PATH="${PYENV_ROOT}/bin:${PATH}" eval "$(pyenv init -)" fi
Above codes set pyenv location, so terminal can execute pyenv commands.
4. Make .bashrc effect
source ~/.bashrc
1. check available versions of python
pyenv install –list
2. Install python 2 and python 3
pyenv install 2.7.11pyenv install 3.4.4
3. Check installed python
pyenv versions
Output:
* system (set by /home/jack/.pyenv/version) 2.7.11 3.4.4
pyenv global 3.4.4pyenv global system
Uninstall python
pyenv uninstall x.x.x
Pyenv has installed the vitrualenv plugin, so we need not install vitrualenv again.
1. Create a vitrual environment of python 3
pyenv virtualenv 3.4.4 env3
Above command creates a python virtual environment named env3. env3 is located at ~/.pyenv/versions/.
Command ‘pyenv versions’ could display current virtual environment:
* system (set by /home/jack/.pyenv/version) 2.7.11 3.4.4
env3
Switch to env3
pyenv activate env3
Now you can do anything in env3 and won’t effect system and other virtual environments.
Switch back to system environment
pyenv deactivate
Delete a virtual environment
rm -rf ~/.pyenv/versions/env3/