Skip to content

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

@myartsev

Description

@myartsev
  • 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 <[email protected]>"]
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions