Skip to content
The Chat Archive
claude-opus-4-20250514-thinking-16k· Anthropic LMArena Human Preference 140K

within a pyproject.toml file, using uv with setuptools as the build backend, how can I…

  1. User

    within a pyproject.toml file, using uv with setuptools as the build backend, how can I specify a dependency which is to be installed only if the operating system is not Windows, or if it is for Linux or Linux / MacOS only?

  2. Assistant

    In a pyproject.toml file with setuptools as the build backend, you can specify platform-specific dependencies using PEP 508 environment markers. Here's how to handle each case:

    Not Windows

    [project]
    dependencies = [
        "some-package; platform_system != 'Windows'",
        # or alternatively:
        "some-package; sys_platform != 'win32'",
    ]
    

    Linux Only

    [project]
    dependencies = [
        "linux-only-package; platform_system == 'Linux'",
        # or alternatively:
        "linux-only-package; sys_platform == 'linux'",
    ]
    

    Linux or macOS Only

    [project]
    dependencies = [
        "unix-package; platform_system in 'Linux Darwin'",
        # or using sys_platform:
        "unix-package; sys_platform in 'linux darwin'",
    ]
    

    Complete Example

    Here's a complete pyproject.toml example:

    [build-system]
    requires = ["setuptools>=61.0"]
    build-backend = "setuptools.build_meta"
    
    [project]
    name = "myproject"
    version = "0.1.0"
    dependencies = [
        "requests>=2.28.0",  # installed on all platforms
        "pywin32; platform_system == 'Windows'",  # Windows only
        "python-daemon; platform_system != 'Windows'",  # Not on Windows
        "pyinotify; platform_system == 'Linux'",  # Linux only
        "watchdog; platform_system in 'Linux Darwin'",  # Linux or macOS
    ]
    

    Key Environment Markers

    The main markers for platform detection are:

    • platform_system: Returns 'Windows', 'Linux', 'Darwin' (for macOS), etc.
    • sys_platform: Returns 'win32', 'linux', 'darwin', etc.

    Both work, but platform_system is often more readable. The environment markers are evaluated at installation time, so the appropriate dependencies will be installed based on the target platform.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.