Current Python version (3.9.7) is not allowed by the project (^3.11)
Asked Answered
S

2

6

We have a poetry project with a pyproject.toml file like this:

[tool.poetry]
name = "daisy"
version = "0.0.2"
description = ""
authors = [""]

[tool.poetry.dependencies]
python = "^3.9"
pandas = "^1.5.2"
DateTime = "^4.9"
names = "^0.3.0"
uuid = "^1.30"
pyyaml = "^6.0"
psycopg2-binary = "^2.9.5"
sqlalchemy = "^2.0.1"
pytest = "^7.2.0"

[tool.poetry.dev-dependencies]
jupyterlab = "^3.5.2"
line_profiler = "^4.0.2"
matplotlib = "^3.6.2"
seaborn = "^0.12.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

When I change the file to use Python 3.11 and run poetry update we get the following error:

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

I only have one env:

> poetry env list
daisy-Z0c0FuMJ-py3.9 (Activated)

Strangely this issue does not occur on my Macbook, only on our Linux machine.

Sigismundo answered 8/2, 2023 at 11:13 Comment(0)
G
6

Poetry cannot update the Python version of an existing venv. Remove the existing one and run poetry install again.

Guacharo answered 9/2, 2023 at 5:41 Comment(0)
C
2

There are a few things that you need to do.

  1. Start by getting rid of the old virtual environment:
    poetry env remove old-environment
    rm poetry.lock

  2. Update pyproject.toml to use the version of Python you want to use:
    python = "^3.11", in your case.

  3. Refer Poetry to the new Python executable:
    poetry env use path-to-the-new-python-3.11

  4. Rebuild your virtual environment:
    poetry install

This will link to Python 3.11 and install all your dependencies in a new virtual environment.

Corrinnecorrival answered 16/4, 2024 at 20:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.