Skip to content

Commit a3b186a

Browse files
committed
Normalize sys.prefix for old virtualenv
virtualenv<14 does not normalize sys.prefix correctly, so we need to do it on our own.
1 parent fcadb92 commit a3b186a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/pip/_internal/locations/_distutils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,20 @@ def get_scheme(
138138

139139

140140
def get_bin_prefix() -> str:
141+
# XXX: In old virtualenv versions, sys.prefix can contain '..' components,
142+
# so we need to call normpath to eliminate them.
143+
prefix = os.path.normpath(sys.prefix)
141144
if WINDOWS:
142-
bin_py = os.path.join(sys.prefix, "Scripts")
145+
bin_py = os.path.join(prefix, "Scripts")
143146
# buildout uses 'bin' on Windows too?
144147
if not os.path.exists(bin_py):
145-
bin_py = os.path.join(sys.prefix, "bin")
148+
bin_py = os.path.join(prefix, "bin")
146149
return bin_py
147150
# Forcing to use /usr/local/bin for standard macOS framework installs
148151
# Also log to ~/Library/Logs/ for use with the Console.app log viewer
149-
if sys.platform[:6] == "darwin" and sys.prefix[:16] == "/System/Library/":
152+
if sys.platform[:6] == "darwin" and prefix[:16] == "/System/Library/":
150153
return "/usr/local/bin"
151-
return os.path.join(sys.prefix, "bin")
154+
return os.path.join(prefix, "bin")
152155

153156

154157
def get_purelib() -> str:

0 commit comments

Comments
 (0)