pythonpippython-packagingpyproject.toml

python pyproject.toml - arch dependency solved on install


In pyproject.toml we have a optional-dependencies for a windows package:

[project.optional-dependencies]
windows = [
    "pywinpty>=2.0.14"
]

To install:

# on windows
pip install .[windows]
# on linux/mac we use the enclosed pty
pip install .

Is it possible so pip install . does this check automatic?

Or uv pip install . (pywinpty is a rust package)


Solution

  • You can use PEP 496 – Environment Markers and PEP 508 – Dependency specification for Python Software Packages; they're usable in setup.py, setup.cfg, pyproject.toml, requirements.txt. In particular in pyproject.toml:

    [project]
    dependencies = [
        "pywinpty>=2.0.14; sys_platform == 'win32'"
    ]