Tags: #python3
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.
sudo pip install virtualenv (installs it globally; ironic I know but this is OK)virtualenv env (env is the dir that’ll be created; this name is common practice)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:
env/bin/pip install <package>To run the Python binary you don’t use the system version; instead:
env/bin/python <...>If you don’t like typing, you can shorten the env/bin so it becomes part of your shell’s environment:
source env/bin/activateTo demonstrate:
which python = /usr/bin/pythonsource env/bin/activatewhich python = ~/Projects/python/foo-project/env/bin/pythonUse
deactivatewhenever using the same shell to swith between projects
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>