python-poetry / python-poetry/poetry

The `poetry install` command does not modify the file `env.toml`

Open
#9,552 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/venv kind/bug status/triage
Dominant language
Python
Stars
34.3k
Forks
2.5k
Avg merge
2d 19h
Merged PRs (30d)
30

Description

Description

Steps to reproduce:

  1. Create a poetry project.
  2. Install two python versions: for example, python 3.12.2 and 3.12.3.
  3. poetry env use /<path to python 3.12.2>/bin/python.
  4. Delete existing env rm -rf $(poetry env info --path).
  5. Create a new one with poetry install (Poetry will use the newest patch version by default 3.12.3).
  6. Run command poetry env use /.../pypoetry/virtualenvs/poetry-project-name/bin/python

Poetry deletes the existing poetry environment with an error: Could not find the python executable /.../pypoetry/virtualenvs/poetry-project-name/bin/python

Workarounds

Manually change the version of the interpreter in the file env.toml.

In my example from 3.12.2 to 3.12.3.

Poetry Installation Method

system package manager (eg: dnf, apt etc.)

Operating System

MacOS Sonoma 14.3.1

Poetry Version

1.7.1

Poetry Configuration
cache-dir = "/Users/Egor.Eliseev/Library/Caches/pypoetry"
experimental.system-git-client = false
installer.max-workers = null
installer.modern-installation = true
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"  # /Users/Egor.Eliseev/Library/Caches/pypoetry/virtualenvs
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"
warnings.export = true
Python Sysconfig

No response

Example pyproject.toml
[tool.poetry]
name = "poetry-pro"
version = "0.1.0"
description = ""
authors = ["Some Dev <somedev@mail.com>"]
packages = []

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

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Poetry Runtime Logs
Stack trace:

  8  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/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  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/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  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/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  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/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  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/cleo/application.py:457 in _run_command
      455│ 
      456│             if command_event.command_should_run():
    → 457│                 exit_code = command.run(io)
      458│             else:
      459│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

  3  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/cleo/commands/base_command.py:117 in run
      115│         io.input.validate()
      116│ 
    → 117│         return self.execute(io) or 0
      118│ 
      119│     def merge_application_definition(self, merge_args: bool = True) -> None:

  2  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/cleo/commands/command.py:61 in execute
       59│ 
       60│         try:
    →  61│             return self.handle()
       62│         except KeyboardInterrupt:
       63│             return 1

  1  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/poetry/console/commands/env/use.py:24 in handle
       22│             return 0
       23│ 
    →  24│         env = manager.activate(self.argument("python"))
       25│ 
       26│         self.line(f"Using virtualenv: {env.path}")

  PythonVersionNotFound

  Could not find the python executable /.../pypoetry/virtualenvs/poetry-project-name-py3.12/bin/python

  at /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/poetry/utils/env/env_manager.py:141 in activate
      137│             pass
      138│ 
      139│         python_path = self._full_python_path(python)
      140│         if python_path is None:
    → 141│             raise PythonVersionNotFound(python)
      142│ 
      143│         try:
      144│             python_version_string = subprocess.check_output(
      145│                 [python_path, "-c", GET_PYTHON_VERSION_ONELINER], text=True

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with poetry/console/commands/env/use.py and poetry/utils/env/env_manager.py, especially the activation path around line 141, then reproduce the listed Python-version switch sequence. Trace how poetry install records the selected interpreter in env.toml. Done means the recorded interpreter matches the newly created environment and the subsequent poetry env use command no longer rejects its executable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
44/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.