PYENV Introduction--debian/ubuntu Managing multiple versions of Python
may ST, 9:00am | COMMENTS
Pyenv is a tool for managing Python versions, and it supports switching between multiple Python versions.
First, install the pyenv
1 |
git clone https://github.com/yyuu/pyenv.git ~/.pyenv
|
Add PYENV_ROOT
and pyenv init
join Bash's ~/.BASHRC (or Zsh's ~/.ZSHRC)
123 |
echo ‘export PATH=~/.pyenv/bin:$PATH‘ >> ~/.bashrcecho ‘export PYENV_ROOT=~/.pyenv‘ >> ~/.bashrcecho ‘eval "$(pyenv init -)"‘ >> ~/.bashrc
|
Second, the pyenv Common command list can be installed Python version
In addition to the official Python version, it also supports
- Anaconda
- IronPython
- Jython
- Miniconda
- PyPy
- Stackless
Install the specified version of Python
12 |
pyenv install 3.5.1pyenv rehash
|
It will automatically download and compile the specified version of the Python source code, which requires a system installation:
1 |
sudo apt-get install -y build-essential zlib1g-dev libssl-dev
|
You can also choose to install:
1 |
sudo apt-get install libsqlite3-dev libbz2-dev libreadline-dev
|
After the installation is complete:
- The source code (such as ~/python-3.5.1.tar.gz) is cached in the. Pyenv/cache directory and can be deleted manually after installation.
- The Python version is installed in the ~/.pyenv/versions directory.
Uninstalling the specified version of Python
Set the Python version of the shell
Equivalent to
1 |
export PYENV_VERSION=3.5.1
|
ClearPYENV_VERSION
Third, installation pyenv-virtualenv
Pyenv-virtual is a pyenv plug-in that supports managing multiple virtualenv
12 |
git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenvecho ‘eval "$(pyenv virtualenv-init -)"‘ >> ~/.bash_profile
|
Create Virtualenv
1 |
pyenv virtualenv 3.5.1 aiohttp-virtual-env
|
- Before you create a aiohttp-virtual-env, you must install the Python 3.5.1 (installed through the system or pyenv).
- Aiohttp-virtual-env is stored in the ~/.pyenv/versions/3.5.1/envs directory, and a symbolic link with the same name is established in the ~/.pyenv/versions directory.
Delete Virtualenv
1 |
pyenv uninstall aiohttp-virtual-env
|
List virtualenv
Activating/Disabling Virtualenv
12 |
pyenv activate aiohttp-virtual-envpyenv deactivate
|
PYENV Introduction--debian/ubuntu Managing multiple versions of Python