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
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-python
totrue
See the similar answer which actually helped me
I would suggest to install Poetry with the specific Python version that you need via
pipx
.Steps:
Uninstall
poetry
.Install
pipx
.Install
poetry
with the needed Python version.pipx install --python python3.12 poetry
Create new environments with
poetry
so thatpyproject.toml
haspython = "^3.12"
.poetry new statements