Ben Shi

Blog Post

virtualenv 101

Posted Under: notes
September 21, 2014

virtualenv is a tool that allow users to create an isolated Python environment. It works by creating a working copy of Python runtime (specified by you) specific to a project without polluting other projects.

Installation

$ pip install virtualenv

Usage

$ mkdir ~/prj/envs; cd ~/prj/envs

# creating virtual env
$ virtualenv myfirstenv  # use -p to specify Python runtime of your choice

# activating env
$ . myfirstvenv/bin/activate

# install other libraries, installation will stay local to the virtual env
$ pip install Flask # e.g. Flask, Django etc...

# deactivate env
$ deactivate

Note

Rather than managing the environments manually. You can use virtualenvwrapper (available via pip) to manage virtual environments.

Usage

# create env
$ mkvirtualenv myfirstenv

# activate env
$ workon myfirstenv

# deactivate env
$ deactivate

# remove env
$ rmvirtualenv myfirstenv

#list all envs
$ lsvirtualenv

Ben Shi

I'm Ben Shi, a Sydney-based Full Stack Software Engineer specialising in micro-services and API development. This is a playground for me to document my learnings and experiences as a technologist.

You can find out a little bit more about me over here.

Contact: [email | twitter| linkedin]