Skip to content

Commit e140322

Browse files
committed
Disallow --user installs if site.ENABLE_USER_SITE is False. (#8794)
1 parent ffbe932 commit e140322

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

news/8794.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevent --user installs if site.ENABLE_USER_SITE is set to False.

src/pip/_internal/commands/install.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ def decide_user_install(
633633
logger.debug("Non-user install by explicit request")
634634
return False
635635

636+
# If we have been asked for a user install explicitly, check compatibility.
636637
if use_user_site:
637638
if prefix_path:
638639
raise CommandError(
@@ -644,6 +645,13 @@ def decide_user_install(
644645
"Can not perform a '--user' install. User site-packages "
645646
"are not visible in this virtualenv."
646647
)
648+
# Catch all remaining cases which honour the site.ENABLE_USER_SITE
649+
# value, such as a plain Python installation (e.g. no virtualenv).
650+
if not site.ENABLE_USER_SITE:
651+
raise InstallationError(
652+
"Can not perform a '--user' install. User site-packages "
653+
"are disabled for this Python."
654+
)
647655
logger.debug("User install by explicit request")
648656
return True
649657

0 commit comments

Comments
 (0)