Pyenv is a Python version management tool that enables global version switching among multiple Python versions
Pyenv installation and configuration on ubuntu:
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
You can check the python versions that can be installed by running the following command:
pyenv install --list
Before installation, you must install the dependencies required by python:
sudo apt-get install libc6-dev gcc sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm
After the above dependencies are installed, you can install python (version optional):
pyenv install 3.4.3 -v
This command will download the source code of python from github, extract it to the directory, and then execute the compilation. If the dependent package is not installed, a compilation error will occur, and the command needs to be re-executed after the installation of the dependent package.
After the installation is complete, you need to use the following command to update the database:
pyenv rehash
Then check the currently installed python version:
pyenv versions * system (set by /home/wang/.pyenv/version) 3.4.3
Next, set the global python version:
pyenv global 3.4.3 pyenv versions system * 3.4.3 (set by /home/wang/.pyenv/version)
Finally confirm the python version:
python
Python 3.4.3 (default, Mar 12 2017, 11:16:03)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
virtual environment
Install the python virtual environment virtualenv and virtualenvwrapper. In a multi-version python environment, it can create an independent python environment, so that multiple python versions do not affect each other.
virtualenv installation command: pip install virtualenv or pip3 install virtualenv
virtualenvwrapper installation command: pip install virtualenvwrapper or pip3 install virtualenvwrapper
Then configure in .basher:
export WORKON_HOME=$HOME/.virtualenvs export PROJECT_HOME=$HOME/workspace export WORKON_HOME=~/Envs source /home/wang(username)/.pyenv/versions/3.4.3/bin/virtualenvwrapper.sh
pyenv terminal command:
pyenv install 3.xx //Install the specified version pyenv uninstall 3.xx //Uninstall the specified version pyenv global 3.xx //Set the global python version pyenv local 3.xx //Set the local version for the program pyenv versions //View all versions of python currently installed pyenv version //View the python version currently in use
Use the command for virtual environment:
mkvirtualenv (environment name) create an environment
rmvirtualenv (environment name) removes an environment
workon (environment name) activate
deactivate exit
workon lists all environment names
lsvirtualenv -b lists all environment names