[Python] pyenv and virtualenv installation, multi-version python multi-project management

Stepped on a lot of pits, recorded about this test, this test environment: Linux centos7 64 bits.

pyenv python is a version management tool, it is capable of switching the global version of python may also be provided corresponding to a single python version items pyenv later use, can be installed in a plurality of different versions of python on the server, version switch convenience can be more good to meet our needs.

virtualenv is a management tool for different projects, different projects to isolate the working environment, to achieve different environmental needs in the same python version.

pyenv used in conjunction with virtualenv, we can better manage our environment python in Linux systems.

1, start prenv installation:

Download the project to the local

1 yum install git -y
2 git clone https://github.com/pyenv/pyenv.git ~/.pyenv

Configuration environment variable

1 echo 'export PATH=~/.pyenv/bin:$PATH' >> ~/.bashrc
2 echo 'export PYENV_ROOT=~/.pyenv' >> ~/.bashrc
3 echo 'eval "$(pyenv init -)"' >> ~/.bashrc

source command to reload the configuration file:

1 source ~/.bashrc
1  # Verify pyenv is properly installed: 
2 pyenv - Help
 3  
4  # View pyenv support the installation of python version: 
5 pyenv install --list

Installation at the dependencies of python:

1 yum install gcc -y
2 yum install openssl-devel bizp2-devel expat-devel gdbm-devel readline-devel sqlite-devel libffi-devel -y

Here we will be able to use pyenv install a different version of python, here 3.7.2 and 2.7.5 are to be installed python version.

1 pyenv install -v 3.7.2
2 pyenv install -v 2.7.5

Here are a few pyenv commonly used commands:

1  # see the currently installed version of python 
2  pyenv versions
 . 3  
. 4  # toggle the current version of python 
. 5 pyenv Global 3.7.2
 . 6  
. 7  # deleted version python 
. 8 pyenv Uninstall 2.7.2

pyenv installation is complete!

2, to begin the installation pyenv-virtualenv

Download the project to the local

1 git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
1  # configure the environment variables 
2 echo ' echo ' the eval " $ (the virtualenv-pyenv the init -) " ' >> ~ / .bash_profile 
. 3  
. 4  # Source command to reload the configuration file: 
. 5 Source ~ / .bashrc
 . 6  
. 7  # see if successful installation 
8 pyenv Help virtualenv

Creating python2.7.5 version of the virtual work environment: project_27_1 and create python3.7.2 version of the virtual work environment: project_37_1

1 pyenv virtualenv 2.7.5 project_27_1
2 pyenv virtualenv 3.7.2 project_37_1
1  # View Create a work environment 
2 pyenv virtualenvs

Example:

1  # into the environment project_27_1 
2  pyenv of an activate project_27_1
 3  # in the environment installed version 0.8 of the Flask 
4 == 0.8 PIP install the Flask
 5  # to exit the current working environment 
6  pyenv deactivate
 7  
8  # delete virtual environment first_project 
9 pyenv virtualenv- the Delete project_27_1

 

Guess you like

Origin www.cnblogs.com/hongming/p/11365551.html