python-setup: Fix site-package selection for unix

This commit is contained in:
Rasmus Wriedt Larsen 2023-01-13 14:41:00 +01:00
Родитель 4bd9723e2b
Коммит 5ed1e985c2
Не найден ключ, соответствующий данной подписи
1 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -19,12 +19,16 @@ except ImportError:
# 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])