Wrong Python version used when virtualenvs.create=false
combined with use-poetry-python
#10226
Labels
virtualenvs.create=false
combined with use-poetry-python
#10226
Description
When using
POETRY_VIRTUALENVS_CREATE="false"
combined withPOETRY_VIRTUALENVS_USE_POETRY_PYTHON="true"
, if a project's declaredrequires-python
doesn't match the Python used by Poetry, thenpoetry sync
won't fail with a "version not compatible error" (as expected), but instead will proceed to sync using the wrong Python version.This leads to confusing UX for end users of Heroku, if the version specified via their
.python-version
file (which is what controls the Python version installed for their app) doesn't match the Python versions in theirpyproject.toml
.I believe this is because the conditional here needs additional handling for the value of
create_venv
(which is the value ofvirtualenvs.create
):poetry/src/poetry/utils/env/env_manager.py
Lines 424 to 428 in 79c207b
Steps to reproduce
Dockerfile
with the below contents.docker build . --progress plain --no-cache
(Note: I've created this
Dockerfile
as the easiest way to provide a minimal testcase; on Heroku we actually don't use Docker like this and install things in a slightly different way)Expected
For
poetry sync
to exit non-zero, with an error message that makes it clear that the Python version is incompatible (since the Poetry Python, which is also the first python on PATH, is 3.13, but yet therequires-python
lists Python 3.12) - so end users know they need to fix their project'srequires-python
or else change the Python in the environment.ie: The
NoCompatiblePythonVersionFoundError
error hereActual
poetry sync
outputs:...where Python 3.12 is actually the distro Python, not the Poetry Python - meaning Poetry has ignored what was configured via
POETRY_VIRTUALENVS_USE_POETRY_PYTHON="true"
, and tried to find its own Python instead (which is something we don't want it to do).In addition, even though Poetry said it was using Python 3.12, it actually goes on to use Poetry Python after all, and so installs the project into a Python 3.13 environment, even though the project isn't compatible with 3.13. As confirmed by the
print(typing_extensions)
step returning:This means the end-user build would appear to succeed, only for the app to potentially crash at run-time when the image is rolled out.
Workarounds
I couldn't find any.
Poetry Installation Method
install.python-poetry.org
Operating System
Debian
Poetry Version
2.1.1
Poetry Configuration
Python Sysconfig
sysconfig.log
Example pyproject.toml
Poetry Runtime Logs
poetry-runtime.log
The text was updated successfully, but these errors were encountered: