Don't sudo pip install in virtual environments

Dec 24, 2015

Deploying python projects in virutal environemnts is a fairly standard practice. Such a deployment process could include a step to install all required python modules from a requirement file like so:

(your_virtual_env)> pip install -r requirements.txt

Does it seem a bit odd that we didn't use sudo with pip install? If you are used to with globally installing python modules in your dev environment, you probably did sudo all the time with pip install. But we shouldn't use sudo in this case because that will cause the python modules to be installed globally. This completely defeats the purpose of a virtual environment.

While debugging a deployment, if you notice that the python modules are not installed in the expected virtual environment folder, you may like to check how they were installed in the first place i.e. with or without sudo.