skip to Main Content

When using Poetry to create a new project with poetry new project-name, it consistently defaults to Python 3.10, despite having Python 3.12 installed on my Ubuntu system. Although I managed to configure Python’s global version to 3.12, this adjustment occurred after installing Poetry. Consequently, Poetry persists in using Python 3.10 for new projects. Here’s the contents of the pyproject.toml file that poetry created:

[tool.poetry]
name = "statements"
version = "0.1.0"
description = ""
authors = ["Sajid Munawar <[email protected]>"]
readme = "README.md"

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


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

I’ve attempted using poetry env use path/to/python3.12, which successfully updates the virtual environment for the current project. However, this command is specific to the current project and doesn’t affect future projects created with Poetry.

How can I ensure that Poetry uses Python 3.12 by default for new projects, even after the global Python version has been updated?

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution that worked for me. To enable Poetry to pick up the currently activated version of Python, you have to set the config option virtualenvs.prefer-active-pythonto true

    See the similar answer which actually helped me


  2. I would suggest to install Poetry with the specific Python version that you need via pipx.

    Steps:

    1. Uninstall poetry.

    2. Install pipx.

    3. Install poetry with the needed Python version.

      pipx install --python python3.12 poetry

    4. Create new environments with poetry so that pyproject.toml has python = "^3.12".

      poetry new statements

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search