python-poetry/poetry · warning · ValueError

<warning>Environment "{name}" does not exist.</warning>

Error message

<warning>Environment "{name}" does not exist.</warning>

What it means

Raised as ValueError in EnvManager.remove when the interpreter probe succeeded and Poetry computed the expected venv name (base_env_name + '-py' + minor) but that directory does not exist under virtualenvs_path. The env was expected for the discovered python version but is absent.

Source

Thrown at src/poetry/utils/env/env_manager.py:343

            pass

        try:
            python_version_string = subprocess.check_output(
                [python, "-c", GET_PYTHON_VERSION_ONELINER],
                text=True,
                encoding="locale",
            )
        except CalledProcessError as e:
            raise EnvCommandError(e)

        python_version = Version.parse(python_version_string.strip())
        minor = f"{python_version.major}.{python_version.minor}"

        name = f"{self.base_env_name}-py{minor}"
        venv_path = venv_path / name

        if not venv_path.exists():
            raise ValueError(f'<warning>Environment "{name}" does not exist.</warning>')

        if self.envs_file.exists():
            self.envs_file.remove_section(self.base_env_name, minor)

        self.remove_venv(venv_path)

        return VirtualEnv(venv_path, venv_path)

    def use_in_project_venv(self) -> bool:
        in_project: bool | None = self._poetry.config.get("virtualenvs.in-project")
        if in_project is not None:
            return in_project

        return self.in_project_venv.is_dir()

    def in_project_venv_exists(self) -> bool:
        in_project: bool | None = self._poetry.config.get("virtualenvs.in-project")
        if in_project is False:

View on GitHub (pinned to 92b74dcfe3)

Solutions

  1. Check 'poetry env list' to see which envs actually exist for this project.
  2. If using in-project venvs, remove the .venv directory manually instead.
  3. Confirm virtualenvs_path config matches where envs were created.
  4. Treat as informational if the env is already gone - nothing to remove.

Example fix

// before
manager.remove("3.12")  # no myproject-py3.12 dir exists -> ValueError

// after - remove a version that has an env
manager.remove("3.11")
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def expected_venv_exists(manager, python_version: str) -> bool:
    from poetry.core.constraints.version import Version
    v = Version.parse(python_version)
    minor = f"{v.major}.{v.minor}"
    name = f"{manager.base_env_name}-py{minor}"
    return (manager._poetry.config.virtualenvs_path / name).exists()

Type guard

def is_missing_env_value_error(e: Exception) -> bool:
    return isinstance(e, ValueError) and 'does not exist' in str(e)

Try / catch

try:
    manager.remove("3.12")
except ValueError as e:
    if 'does not exist' in str(e):
        # no env for this version - nothing to remove
        pass
    else:
        raise

Prevention

When it happens

Trigger: Calling 'poetry env remove <python-version-or-interpreter>' where the version resolves correctly but no venv directory '{base_env_name}-py{minor}' exists (env_manager.py:339-343).

Common situations: Asking to remove a python version's env that was never created; the env was already removed; the venv was created in-project (virtualenvs.in-project=true) so nothing lives in virtualenvs_path; virtualenvs_path was changed/relocated.

Related errors


AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04). Data as JSON: /data/errors/777dd1616ac96168.json. Report an issue: GitHub.