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?
I would suggest to install Poetry with the specific Python version that you need via
pipx.Steps:
Uninstall
poetry.Install
pipx.Install
poetrywith the needed Python version.pipx install --python python3.12 poetryCreate new environments with
poetryso thatpyproject.tomlhaspython = "^3.12".poetry new statements