Skip to content

Display warning when 'SUDO_COMMAND' in os.environ #2403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pip/basecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os
import sys
import textwrap
import traceback
import optparse
import warnings
Expand Down Expand Up @@ -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():
Expand Down