Skip to content

Latest commit

 

History

History
36 lines (31 loc) · 1.92 KB

20230104.org

File metadata and controls

36 lines (31 loc) · 1.92 KB

Poetry dependency resolution and Python versions

In a virtualenv using Python 3.9.15, a poetry install failed with the following message:

Updating dependencies
Resolving dependencies...

The current project's Python requirement (>=3.9,<4.0) is not compatible with some of the required packages Python requirement:
  - numpy requires Python >=3.7,<3.11, so it will not be satisfied for Python >=3.11,<4.0

As Python 3.9.1 satisfies both the “current project’s Python requirement” and that of numpy, I wondered why the command failed. Some googling lead me to this question in the poetry FAQ:

Unlike pip, Poetry doesn’t resolve for just the Python in the current environment. Instead it makes sure that a dependency is resolvable within the given Python version range in pyproject.toml.

It took me a while to let this sink in but it totally makes sense: you have a project that states “I work with Python >=3.9,<4.0” even though one of its dependencies states “I only work with Python >=3.7,<3.11”. They cannot both be right so Poetry does the right things and aborts.

This brings me to another point: the Python requirement “>=3.9,<4.0” makes sense if Python adheres to semantic versioning. Unfortunately, according to this discussion, it does not:

Despite similarities, Python does not use the popular semantic versioning_ scheme, which was published several decades after Python.

This doesn’t mean Python 3.11 isn’t compatible to a Python 3.9 for a particular code base, but there are no guarantees that it is. So you might want to rethink a Python requirement like “>=3.9,<4.0”.