Skip to content

Commit 82a2f35

Browse files
committed
Make --require-virtualenv output more info
if not in a virtualenv **and** --user wasn't specified. Previously, this would print an error even if --user was specified. I believe the spirit of `--require-virtualenv` is that it was meant to be used as `require_virtualenv = True` in the pip config file and what it really seeks to do is to prevent the user from messing with packages in the system python envvironment. Thus, I'd argue that --user shouldn't cause an error, because it doesn't mess with the system python. With this change, output looks like this: $ python -m pip install --require-virtualenv foo ****************************************************** Using pip outside a virtualenv and without --user is not recommended! Doing stuff with the system python's packages can break your system. Did you mean to use a virtualenv or use --user? ******************************************************
1 parent 4d5eff4 commit 82a2f35

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pip/basecommand.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import os
66
import sys
7+
import textwrap
78
import traceback
89
import optparse
910
import warnings
@@ -214,10 +215,20 @@ def main(self, args):
214215
if options.require_venv:
215216
# If a venv is required check if it can really be found
216217
if not running_under_virtualenv():
217-
logger.critical(
218-
'Could not find an activated virtualenv (required).'
219-
)
220-
sys.exit(VIRTUALENV_NOT_FOUND)
218+
if not getattr(options, 'use_user_site'):
219+
logger.critical(
220+
textwrap.dedent("""\
221+
******************************************************
222+
Using pip outside a virtualenv and without --user
223+
is not recommended!
224+
225+
Doing stuff with the system python's packages can break
226+
your system.
227+
228+
Did you mean to use a virtualenv or use --user?
229+
******************************************************""")
230+
)
231+
sys.exit(VIRTUALENV_NOT_FOUND)
221232

222233
# Check if we're using the latest version of pip available
223234
if (not options.disable_pip_version_check and not

0 commit comments

Comments
 (0)