Skip to content

Commit 5ed1e98

Browse files
committed
python-setup: Fix site-package selection for unix
1 parent 4bd9723 commit 5ed1e98

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

python-setup/find_site_packages.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
# poetry/requests-3, I was not allowed to install pip! So I did not pursue this
2020
# option further.
2121
#
22-
# Instead, testing (on both Windows and Linux) shows that the last entry of
23-
# `site.getsitepackages()` has the right path (note: On linux there is only a single
24-
# entry), whereas `site.getusersitepackages()` is about the system python (very
25-
# confusing).
22+
# Instead, testing `site.getsitepackages()` contains has the right path, whereas
23+
# `site.getusersitepackages()` is about the system python (very confusing).
2624
#
2725
# We can't use the environment variable POETRY_VIRTUALENVS_OPTIONS_NO_PIP because it
2826
# does not work, see https://github.com/python-poetry/poetry/issues/5906
2927
import site
30-
print(site.getsitepackages()[-1])
28+
29+
if sys.platform.startswith("win32"):
30+
# On windows, the last entry of `site.getsitepackages()` has the right path
31+
print(site.getsitepackages()[-1])
32+
else:
33+
# on unix, the first entry of `site.getsitepackages()` has the right path
34+
print(site.getsitepackages()[0])

0 commit comments

Comments
 (0)