diff --git a/pip/basecommand.py b/pip/basecommand.py index 28e22b6731c..876d2434f39 100644 --- a/pip/basecommand.py +++ b/pip/basecommand.py @@ -4,6 +4,7 @@ import logging import os import sys +import textwrap import traceback import optparse import warnings @@ -211,6 +212,27 @@ def main(self, args): if options.exists_action: os.environ['PIP_EXISTS_ACTION'] = ' '.join(options.exists_action) + if 'SUDO_COMMAND' in os.environ: + logger.warning( + textwrap.dedent("""\ + ****************************************************** + Are you using sudo? Using pip with sudo can be tricky. + + If you're using a virtualenv: + + Sudo usually won't pass the environment variables + that are set by virtualenv's `activate` scripts, so + a `sudo pip install` may not run in the virtualenv. + + If you're installing to the system python: + + This is risky and can lead to system breakage. + Usually it is better to use your OS package manager + to manage your system python and to use pip in a + virtualenv or with the --user option. + ******************************************************""") + ) + if options.require_venv: # If a venv is required check if it can really be found if not running_under_virtualenv():