Search code examples
pythonsetuptools

Pip: Invalid requirement


I'm trying to install a custom package for my project using pip install. The project is using setuptools to create a .whl file.

When trying to install pip like below command, I'm getting error: Invalid requirement.

pip install target/custom_utils-2.0.0_SNAPSHOT-py3-none-any.whl

Error:

ERROR: Invalid requirement: 'custom_utils==2.0.0_SNAPSHOT': Expected end or semicolon (after version specifier)
    custom_utils==2.0.0_SNAPSHOT
                ~~~~~~~^

This version is violating PEP 440, but setuptool==65.5.1 was still able to handle this. The strange part is, this was working till yesterday. I'm not sure if something changed during night.


Solution

  • Possibly a pip issue. There's a recent release that removes support for non-standard version specifiers. Try pinning pip to pip<24.

    See https://pip.pypa.io/en/stable/news/#b1-2024-05-06

    Remove support for legacy versions and dependency specifiers.

    Packages with non standard-compliant versions or dependency specifiers are now ignored by the resolver. Already installed packages with non standard-compliant versions or dependency specifiers must be uninstalled before upgrading them

    If you control the version schema of custom_utils, then you can swap the _ for a +, and pip will be more permissive of what comes after the plus. For example: custom_utils==2.0.0+SNAPSHOT would be permitted. Specifically, the bit after the plus is allowed to contain any ASCII letters [a-zA-Z], and digits [0-9] or a period ., and it must not start or end with a period. eg. 2.0.0+SNAPSNOT. would not be allowed, but 2.0.0+SNAP.SHOT would. See https://packaging.python.org/en/latest/specifications/version-specifiers/#local-version-identifiers for more details.