Skip to content
The Chat Archive
deepseek-v3-0324· DeepSeek 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, you can specify platform-specific dependencies using environment markers (PEP 508). When using uv with setuptools as the build backend, you can define conditional dependencies based on the operating system.

    1. Specifying a Dependency for Non-Windows Systems

    To install a dependency only if the OS is not Windows, use:

    [project]
    dependencies = [
        "some-package; sys_platform != 'win32'",
    ]
    

    2. Specifying a Dependency for Linux Only

    To install a dependency only on Linux, use:

    [project]
    dependencies = [
        "some-package; sys_platform == 'linux'",
    ]
    

    3. Specifying a Dependency for Linux or macOS Only

    To install a dependency only on Linux or macOS, use:

    [project]
    dependencies = [
        "some-package; sys_platform == 'linux' or sys_platform == 'darwin'",
    ]
    

    4. Using optional-dependencies for Platform-Specific Extras

    Alternatively, you can define optional dependencies (extras) for different platforms:

    [project.optional-dependencies]
    linux = ["some-package; sys_platform == 'linux'"]
    macos = ["some-package; sys_platform == 'darwin'"]
    non_windows = ["some-package; sys_platform != 'win32'"]
    

    Users can then install them with:

    pip install -e ".[linux]"       # Linux only
    pip install -e ".[non_windows]" # Non-Windows
    

    Key Environment Markers

    MarkerMeaning
    sys_platform == 'win32'Windows
    sys_platform == 'linux'Linux
    sys_platform == 'darwin'macOS
    sys_platform != 'win32'Non-Windows

    Example pyproject.toml

    [build-system]
    requires = ["setuptools"]
    build-backend = "setuptools.build_meta"
    
    [project]
    name = "my-package"
    version = "0.1.0"
    dependencies = [
        "requests",
        "uvloop; sys_platform != 'win32'",  # Only on non-Windows
    ]
    
    [project.optional-dependencies]
    linux = ["pyinotify; sys_platform == 'linux'"]  # Linux-only
    macos = ["pyobjc; sys_platform == 'darwin'"]    # macOS-only
    

    This ensures dependencies are installed only on the specified platforms. 🚀

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