Skip to content

Commit

Permalink
python-setup: Fix site-package selection for unix
Browse files Browse the repository at this point in the history
  • Loading branch information
RasmusWL committed Jan 13, 2023
1 parent 4bd9723 commit 5ed1e98
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions python-setup/find_site_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
# poetry/requests-3, I was not allowed to install pip! So I did not pursue this
# option further.
#
# Instead, testing (on both Windows and Linux) shows that the last entry of
# `site.getsitepackages()` has the right path (note: On linux there is only a single
# entry), whereas `site.getusersitepackages()` is about the system python (very
# confusing).
# Instead, testing `site.getsitepackages()` contains has the right path, whereas
# `site.getusersitepackages()` is about the system python (very confusing).
#
# We can't use the environment variable POETRY_VIRTUALENVS_OPTIONS_NO_PIP because it
# does not work, see https://github.com/python-poetry/poetry/issues/5906
import site
print(site.getsitepackages()[-1])

if sys.platform.startswith("win32"):
# On windows, the last entry of `site.getsitepackages()` has the right path
print(site.getsitepackages()[-1])
else:
# on unix, the first entry of `site.getsitepackages()` has the right path
print(site.getsitepackages()[0])

0 comments on commit 5ed1e98

Please sign in to comment.