« Back to Index

[Python3 Virtual Environment with virtualenv]

View original Gist on GitHub

Tags: #python3

Python3 Virtual Environment with virtualenv.md

Use virtualenv to allow each of your projects to have their own set of dependencies. This is similar to how Ruby has Bundler and Gemfiles so you don’t install certain packages globally.

Avoid commiting env into version control by utilising .gitignore

virtualenv . side-steps the folder creation if you really prefer

Now you can install packages using:

To run the Python binary you don’t use the system version; instead:

If you don’t like typing, you can shorten the env/bin so it becomes part of your shell’s environment:

To demonstrate:

Use deactivate whenever using the same shell to swith between projects

Switching Python versions

So virtualenv will use the default Python version installed (for me it was 2.7.10).

To switch it to using Python 3, execute the following:

virtualenv -p python3 <env>