python steps to build a virtual environment

  • 2020-05-12 02:51:22
  • OfStack

preface

Believe for python developers, the machine has different python version is very normal, because the development of the project in 2.6 or 2.7, 3.0 + in some versions, how to put these different versions of management is good, keep the each environment clean and independent, easy to switch between different versions, this time is going to use our virtual environment, so today we take a look at python build tools pyenv using virtual environment.

1, install,


git clone https://github.com/yyuu/pyenv.git ~/.pyenv

echo  ' export PYENV_ROOT= " $HOME/.pyenv "'  >> ~/.bash_profile

echo  ' export PATH= " $PYENV_ROOT/bin:$PATH "'  >> ~/.bash_profile

echo  ' eval  " $(pyenv init -) "'  >> ~/.bash_profile

exec $SHELL

source ~/.bash_profile

Just log out and log in again.

2. Common commands

pyenv install, list # lists the installable versions of python

pyenv install -v 3.3.5 # install version 3.3.5

pyenv uninstall 3.3.5 # uninstall

pyenv version # view the current version

pyenv global 3.3.5 # switch to version 3.35

3. Install pyenv-virtualenv


git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv  
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
source ~/.bash_profile

4. Create a virtual environment


pyenv virtualenv 2.7.10 env2710

5. Activate the virtual environment


pyenv activate env2710

You can then install the required software in this environment.

6. Quit the virtual environment


pyenv deactivate

conclusion

The above is the whole content of this article, I hope the content of this article can help you to learn or use python, if you have any questions, you can leave a message to communicate.


Related articles: