Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Python version used #1888

Closed
3 tasks done
pikeas opened this issue Jan 14, 2020 · 5 comments
Closed
3 tasks done

Unexpected Python version used #1888

pikeas opened this issue Jan 14, 2020 · 5 comments
Labels
area/venv Related to virtualenv management kind/bug Something isn't working as expected

Comments

@pikeas
Copy link

pikeas commented Jan 14, 2020

  • I am on the latest Poetry version.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

  • OS version and name: macOS 10.15.2

  • Poetry version: 1.0.2

Issue

$ poetry new foo
$ poetry debug
[...]
Virtualenv
Python:         3.8.1
Implementation: CPython
Path:           <user>/Library/Caches/pypoetry/virtualenvs/foo-y-IvgPhK-py3.8
Valid:          True

System
Platform: darwin
OS:       posix
Python:   <user>/.asdf/installs/python/3.8.1

$ ls -l ~/Library/Caches/pypoetry/virtualenvs/foo-y-IvgPhK-py3.8/bin/python
lrwxr-xr-x  1 <user>  staff  49 Jan 14 13:46 <user>/Library/Caches/pypoetry/virtualenvs/foo-y-IvgPhK-py3.8/bin/python -> <user>/.local/pipx/venvs/poetry/bin/python

I manage Python versions with asdf and Poetry with pipx. I expected Poetry to symlink my default Python (the one from asdf), instead it used the one from poetry's environment.

There have been some other issues regarding how Poetry chooses which Python to use. The above behavior seems either incorrect, in which case this is a bug, or counterintuitive, in which case perhaps the docs for poetry new could describe how the Python executable is chosen?

@pikeas pikeas added the kind/bug Something isn't working as expected label Jan 14, 2020
@finswimmer
Copy link
Member

Hello @pikeas,

poetry takes the python version that is available when running python in the environment it is in. That's in behavior I would expect and that's the reason why the recommended installation way is curl. With pip or pipx poetry will always be in it's own environment and will catch up the python that is available there.

fin swimmer

@pikeas
Copy link
Author

pikeas commented Jan 15, 2020

The issue seems to go a bit deeper than that.

With Poetry installed via pipx into Python 3.8.1, a Poetry-managed project running under Python 2.7 displays a warning on every invocation.

[tool.poetry]
name = "foo"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^2.7"

[tool.poetry.dev-dependencies]
pylint = "1.9.5"
yapf = "^0.29.0"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
$ poetry debug

Poetry
Version: 1.0.2
Python:  3.8.1

Virtualenv
Python:         3.8.1
Implementation: CPython
Path:           NA

System
Platform: darwin
OS:       posix
Python:   <user>/.local/pipx/venvs/poetry
$ poetry shell
The currently activated Python version 3.8.1 is not supported by the project (^2.7).
Trying to find and use a compatible version.
Using python2 (2.7.17)
Spawning shell within <user>/Library/Caches/pypoetry/virtualenvs/foo-PxKbcfXG-py2.7

The virtualenv appears to be functional, the warning doesn't seem accurate, and the debug output for the virtualenv is incorrect.

poetry takes the python version that is available when running python in the environment it is in

Is this what causes the unsupported version warning? Why is Poetry validating its active Python against the project's Python?

@Kurt-von-Laven
Copy link

Kurt-von-Laven commented Oct 28, 2021

Poetry used to use the correct version of Python as specified by pyproject.toml and installed via asdf, which uses the old get-poetry.py install script. I don't know what changed (certainly not my Python or Poetry versions, which are pinned to 3.9.7 and 1.1.11, respectively), but suddenly Poetry started creating virtualenvs that used the system version of Python instead. I was able to workaround this by running poetry env use "$ASDF_DIR/shims/python" for each project and removing and recreating each virtualenv. I am running Ubuntu 20.04 LTS via Windows Subsytem for Linux 2, and I noted that the issue did not reproduce on my native Ubuntu 21.10 installation.

@finswimmer
Copy link
Member

Setting virtualenvs.prefer-active-python to true is the correct way now to solve this. See https://python-poetry.org/docs/configuration/#virtualenvsprefer-active-python-experimental

Copy link

github-actions bot commented Mar 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/venv Related to virtualenv management kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

3 participants