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

poetry install does not pick up Python version set by Pyenv on Debian #7262

Closed
4 tasks done
myartsev opened this issue Dec 28, 2022 · 6 comments
Closed
4 tasks done
Labels
status/duplicate Duplicate issues

Comments

@myartsev
Copy link

  • Poetry version: 1.3.1
  • Python version: 3.11.0
  • OS version and name: Debian 11 (Bullseye)
  • pyproject.toml:
[tool.poetry]
name = "***"
version = "***"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
packages = [{include = "***"}]

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


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
  • 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

My project uses Python 3.11 and I'm trying to install it on a vanilla Debian machine.

Debian 11 comes with Python 3.9.2 as the system version of Python.
It is not recommended to override the system version and jeopardize the tested stability of Debian.

So PyEnv comes to the rescue.

Install Pyenv and Python 3.11.0

curl https://pyenv.run | bash
pyenv install 3.11.0

Compile/Install Python 3.11 and make it the global version of Python:

pyenv global 3.11.0
pyenv versions
python3 --version
*restart shell*

Now Python 3.11.0 should be the default

python3 --version

Perfect, let's install Poetry and init a project using Python 3.11.0

curl -sSL https://install.python-poetry.org | python3 -
cd project-path
poetry install

Ooops, somehow Poetry is still picking up Python 3.9.2

***@***:~/code/***$ poetry install -vvv

  Stack trace:

  8  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/application.py:327 in run
      325│
      326│             try:
    → 327│                 exit_code = self._run(io)
      328│             except BrokenPipeError:
      329│                 # If we are piped to another process, it may close early and send a

  7  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/poetry/console/application.py:190 in _run
      188│         self._load_plugins(io)
      189│
    → 190│         exit_code: int = super()._run(io)
      191│         return exit_code
      192│

  6  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/application.py:431 in _run
      429│             io.input.interactive(interactive)
      430│
    → 431│         exit_code = self._run_command(command, io)
      432│         self._running_command = None
      433│

  5  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/application.py:473 in _run_command
      471│
      472│         if error is not None:
    → 473│             raise error
      474│
      475│         return terminate_event.exit_code

  4  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/application.py:454 in _run_command
      452│
      453│         try:
    → 454│             self._event_dispatcher.dispatch(command_event, COMMAND)
      455│
      456│             if command_event.command_should_run():

  3  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/events/event_dispatcher.py:26 in dispatch
       24│
       25│         if listeners:
    →  26│             self._do_dispatch(listeners, event_name, event)
       27│
       28│         return event

  2  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/events/event_dispatcher.py:89 in _do_dispatch
       87│                 break
       88│
    →  89│             listener(event, event_name, self)
       90│
       91│     def _sort_listeners(self, event_name: str) -> None:

  1  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/poetry/console/application.py:299 in configure_env
      297│
      298│         env_manager = EnvManager(poetry, io=io)
    → 299│         env = env_manager.create_venv()
      300│
      301│         if env.is_venv() and io.is_verbose():

  InvalidCurrentPythonVersionError

  Current Python version (3.9.2) is not allowed by the project (^3.11).
  Please change python executable via the "env use" command.

  at ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/poetry/utils/env.py:902 in create_venv
       898│             current_python = Version.parse(
       899│                 ".".join(str(c) for c in env.version_info[:3])
       900│             )
       901│             if not self._poetry.package.python_constraint.allows(current_python):
    →  902│                 raise InvalidCurrentPythonVersionError(
       903│                     self._poetry.package.python_versions, str(current_python)
       904│                 )
       905│             return env
       906│

Interesting output for poetry debug info:

Poetry
Version: 1.3.1
Python:  3.11.0

Virtualenv
Python:         3.9.2
Implementation: CPython
Path:           /home/***/.cache/pypoetry/virtualenvs/***-LecU8Rvu-py3.11
Executable:     /home/***/.cache/pypoetry/virtualenvs/***-LecU8Rvu-py3.11/bin/python
Valid:          True

System
Platform:   linux
OS:         posix
Python:     3.9.2
Path:       /usr
Executable: /usr/bin/python3.9

poetry env use 3.11 does not help either

@myartsev myartsev added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Dec 28, 2022
@finswimmer
Copy link
Member

Hey,

you have to set virtualenvs.prefer-active-python to true (https://python-poetry.org/docs/configuration/#virtualenvsprefer-active-python-experimental) so that Poetry can pick up your current active Python.

poetry env use 3.11 does not help either

Could be same reason as in #7158, which will be fixed by #7221.

fin swimmer

@myartsev
Copy link
Author

Hey,

I've set virtualenvs.prefer-active-python, and it gets picked up during the install, but Python 3.9 is still used as the active python executable later on:

***@localhost:~/code/***$ poetry install -vvv
Loading configuration file /home/***/.config/pypoetry/config.toml
Trying to detect current active python executable as specified in the config.
Found: /home/***/.pyenv/versions/3.11.0/bin/python

  Stack trace:

  8  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/application.py:327 in run
      325│
      326│             try:
    → 327│                 exit_code = self._run(io)
      328│             except BrokenPipeError:
      329│                 # If we are piped to another process, it may close early and send a

  7  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/poetry/console/application.py:190 in _run
      188│         self._load_plugins(io)
      189│
    → 190│         exit_code: int = super()._run(io)
      191│         return exit_code
      192│

  6  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/application.py:431 in _run
      429│             io.input.interactive(interactive)
      430│
    → 431│         exit_code = self._run_command(command, io)
      432│         self._running_command = None
      433│

  5  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/application.py:473 in _run_command
      471│
      472│         if error is not None:
    → 473│             raise error
      474│
      475│         return terminate_event.exit_code

  4  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/application.py:454 in _run_command
      452│
      453│         try:
    → 454│             self._event_dispatcher.dispatch(command_event, COMMAND)
      455│
      456│             if command_event.command_should_run():

  3  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/events/event_dispatcher.py:26 in dispatch
       24│
       25│         if listeners:
    →  26│             self._do_dispatch(listeners, event_name, event)
       27│
       28│         return event

  2  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/cleo/events/event_dispatcher.py:89 in _do_dispatch
       87│                 break
       88│
    →  89│             listener(event, event_name, self)
       90│
       91│     def _sort_listeners(self, event_name: str) -> None:

  1  ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/poetry/console/application.py:299 in configure_env
      297│
      298│         env_manager = EnvManager(poetry, io=io)
    → 299│         env = env_manager.create_venv()
      300│
      301│         if env.is_venv() and io.is_verbose():

  InvalidCurrentPythonVersionError

  Current Python version (3.9.2) is not allowed by the project (^3.11).
  Please change python executable via the "env use" command.

  at ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/poetry/utils/env.py:902 in create_venv
       898│             current_python = Version.parse(
       899│                 ".".join(str(c) for c in env.version_info[:3])
       900│             )
       901│             if not self._poetry.package.python_constraint.allows(current_python):
    →  902│                 raise InvalidCurrentPythonVersionError(
       903│                     self._poetry.package.python_versions, str(current_python)
       904│                 )
       905│             return env
       906│

@finswimmer
Copy link
Member

Hey again,

I guess there is already a venv which contains the wrong Python version. Remove this one and try again.

fin swimmer

@myartsev
Copy link
Author

Yes! I needed to delete /home/***/.cache/pypoetry/virtualenvs and it's working now 👍

Thank you

@neersighted neersighted closed this as not planned Won't fix, can't repro, duplicate, stale Dec 29, 2022
@neersighted neersighted added status/duplicate Duplicate issues and removed kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Dec 29, 2022
@nirvana-msu
Copy link

@finswimmer

I guess there is already a venv which contains the wrong Python version. Remove this one and try again.

While this solves the problem, this still looks more like a bug. It is perfectly normal to want to upgrade Python to the newest patch release - and when you do so, you hit this error with no clue what to do next. At least the error message could be made more helpful. Or better, Poetry could suggest to re-create venv using the new interpreter.

Copy link

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 Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status/duplicate Duplicate issues
Projects
None yet
Development

No branches or pull requests

4 participants