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

Contraditory warning from poetry shell on Poetry 1.2.2 #6938

Open
4 tasks done
staticdev opened this issue Nov 2, 2022 · 6 comments
Open
4 tasks done

Contraditory warning from poetry shell on Poetry 1.2.2 #6938

staticdev opened this issue Nov 2, 2022 · 6 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@staticdev
Copy link

staticdev commented Nov 2, 2022

  • Poetry version: 1.2.2
  • Python version: 3.10.6
  • OS version and name: Debian 11
  • pyproject.toml:

Relevant part:

[tool.poetry.dependencies]
python = ">=3.10.0,<4.0"
click = ">=8.1.1"
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

I have many versions of Python installed with Pyenv, but my settings are:

pyenv local 3.10.6
pyenv global 3.10.6

I have created a virtualenv with poetry install and when I do poetry shell I get:

The currently activated Python version 3.9.2 is not supported by the project (>=3.10.0,<4.0).
Trying to find and use a compatible version. 
Using python3 (3.10.6)
Spawning shell within /home/user/.cache/pypoetry/virtualenvs/project-0KWPzb1N-py3.10

I don't understand this warning since my venv was created with py3.10, my pyenv only has 3.10 and it says python3 (3.10.6).

Then after poetry shell I get error with:

poetry run project
Current Python version (3.9.2) is not allowed by the project (>=3.10.0,<4.0).
Please change python executable via the "env use" command.

Successful env use 3.10.6 and again same error:

env use 3.10.6
Using virtualenv: /home/user/.cache/pypoetry/virtualenvs/project-0KWPzb1N-py3.10
poetry run project
Current Python version (3.9.2) is not allowed by the project (>=3.10.0,<4.0).
Please change python executable via the "env use" command.

I also tried deleting the folder /home/user/.cache/pypoetry/virtualenvs/project-0KWPzb1N-py3.10 and creating again the environment but I get the same warning and errors:

poetry install
The currently activated Python version 3.9.2 is not supported by the project (>=3.10.0,<4.0).
Trying to find and use a compatible version. 
Using python3 (3.10.6)
@staticdev staticdev added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Nov 2, 2022
@finswimmer
Copy link
Member

Hey @staticdev,

by default Poetry will use the interpreter it was installed with to create a new venv. If it should instead take whatever is the activated Python in your current shell set virtualenvs.prefer-active-python to true.

fin swimmer

@staticdev
Copy link
Author

@finswimmer thanks a lot for the prompt response and clarification! It was very helpful =)

I did poetry config virtualenvs.prefer-active-python true and recreated the environment, everything worked. Still I think the behavior is not totally consistent with what you said. When I had poetry config virtualenvs.prefer-active-python false, I used poetry install, it was using python 3.9.2 (probably the version I installed it), but the folder created was named with py3.10. And also I find strange to say:

The currently activated Python version 3.9.2 is not supported by the project (>=3.10.0,<4.0).
Trying to find and use a compatible version. 
Using python3 (3.10.6)

This two points made me confused, even using poetry for years now. Questions:

  1. Would it be the case that, since poetry was using python 3.9.2 the environment folder has py3.9?
  2. Actually, since my project forbids python 3.9 with python = ">=3.10.0,<4.0" maybe then I should get an error right away. This would also prevent confusing messages of warning and error after this point.

@staticdev
Copy link
Author

@finswimmer I am having same problem on Mac, but this time poetry config virtualenvs.prefer-active-python true is not my friend. I always have:

Current Python version ... is not allowed by the project...
Please change python execute via the "use env" command.

poetry use env also does not change the result.

@bikefrivolously
Copy link

bikefrivolously commented Nov 27, 2022

I'm also experiencing a similar issue, which seems to contradict the documentation here: https://python-poetry.org/docs/managing-environments/

By default, Poetry will try to use the Python version used during Poetry’s installation to create the virtual environment for the current project.
However, for various reasons, this Python version might not be compatible with the python requirement of the project. In this case, Poetry will try to find one that is and use it. If it’s unable to do so then you will be prompted to activate one explicitly, see Switching environments.

While I am using pyenv, I don't think the prefer-active-python setting is relevant here. I don't care if poetry uses the currently active version but I would like it to use a version that meets the project dependencies, and it looks like it is trying to :)

Poetry was installed using python 3.9.13 initially. I have 3.9.13 and 3.10.6 available via pyenv. My current project wants ^3.10

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

poetry should look for python 3.10.x and create the virtual environment using the discovered version, or prompt otherwise. From the output, it appears to find 3.10.6 but when I inspect the created virtual environment afterwards, it is python 3.9.13

$ poetry install
The currently activated Python version 3.9.13 is not supported by the project (^3.10).
Trying to find and use a compatible version. 
Using python3 (3.10.6)
Creating virtualenv flask-huey-DOCxGAqz-py3.10 in /home/dmartins/.cache/pypoetry/virtualenvs
....
$ poetry env info

Virtualenv
Python:         3.9.13
Implementation: CPython
Path:           /home/dmartins/.cache/pypoetry/virtualenvs/flask-huey-DOCxGAqz-py3.10
Executable:     /home/dmartins/.cache/pypoetry/virtualenvs/flask-huey-DOCxGAqz-py3.10/bin/python
Valid:          True

System
Platform:   linux
OS:         posix
Python:     3.9.13
Path:       /home/dmartins/.pyenv/versions/3.9.13
Executable: /home/dmartins/.pyenv/versions/3.9.13/bin/python3.9

$ cat  /home/dmartins/.cache/pypoetry/virtualenvs/flask-huey-DOCxGAqz-py3.10/pyvenv.cfg 
home = /home/dmartins/.pyenv/versions/3.9.13/bin
implementation = CPython
version_info = 3.9.13.final.0
virtualenv = 20.16.7
include-system-site-packages = false
base-prefix = /home/dmartins/.pyenv/versions/3.9.13
base-exec-prefix = /home/dmartins/.pyenv/versions/3.9.13
base-executable = /home/dmartins/.pyenv/versions/3.9.13/bin/python3.9
prompt = flask-huey-py3.10

edit: including my current poetry config

cache-dir = "/home/dmartins/.cache/pypoetry"
experimental.new-installer = true
experimental.system-git-client = false
installer.max-workers = null
installer.no-binary = null
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/dmartins/.cache/pypoetry/virtualenvs
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"

edit2:
With virtualenvs.prefer-active-python = true:

  • with 3.9.13 active, poetry looks for a version matching ^3.10 and selects 3.11.0 (Fedora 37 system python) and creates a venv using 3.11.0
  • with 3.10.6 active, poetry creates a 3.10.6 venv
  • with 3.11.0 active, poetry creates a 3.11.0 venv

With virtualenvs.prefer-active-python = false:

  • with 3.9.13 active, poetry looks for a version matching ^3.10 and selects 3.11.0 (Fedora 37 system python) and creates a venv using 3.11.0

  • with 3.10.6 active, poetry creates a 3.9.13 venv (though output suggests it is going to use 3.10.6)

  • with 3.11.0 active (system python), poetry creates a 3.11.0 venv.

@bikefrivolously
Copy link

@staticdev a potential workaround for your initial issue is to run poetry env use before any venv with the -py3.10 suffix exists.

  • remove the venv if it already exists (usually a directory in ~/.cache/pypoetry/virtualenvs/).
  • from your project directory: poetry env use ~/.pyenv/versions/3.10.6/bin/python or poetry env use 3.10 <-- creates the venv with 3.10 python.
  • then run poetry install or poetry shell

@ShadowLNC
Copy link

At a glance, this looks like it might be the same behaviour as #7158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

4 participants