ubuntu安装python虚拟环境并实现多版本共破

admin 2020-9-22 13713

Here I will explain the way virtualenv should be setup along with virtualenvwrapper in ubuntu. It’s a small and easy procedure.


Install pip

sudo apt-get install python-pip


Install virtualenv

sudo pip install virtualenv


Create a dir to store your virtualenvs (I use ~/.virtualenvs)

mkdir ~/.virtualenvs

At this point you are all set to use virtualenv with the standard commands. However, I prefer to use the extra commands included in virtualenvwrapper. Lets set that up.


Install virtualenvwrapper

sudo pip install virtualenvwrapper


Set WORKON_HOME to your virtualenv dir

export WORKON_HOME=~/.virtualenvs


Add virtualenvwrapper.sh to .bashrc

Add this line to the end of ~/.bashrc so that the virtualenvwrapper commands are loaded.

. /usr/local/bin/virtualenvwrapper.sh


Exit and re-open your shell, or reload .bashrc with the command . .bashrc and you’re ready to go.


Create a new virtualenv

mkvirtualenv myawesomeproject

to exit your new virtualenv, use deactivate.


Switch between enviornments with workon

To load or switch between virtualenvs, use the workon command:

workon myawesomeproject


最新回复 (0)
返回