within a pyproject.toml file, using uv with setuptools as the build backend, how can I…
- 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?
- Assistant
In a
pyproject.tomlfile, you can specify platform-specific dependencies using environment markers (PEP 508). When usinguvwithsetuptoolsas 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-dependenciesfor Platform-Specific ExtrasAlternatively, 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-WindowsKey Environment Markers
Marker Meaning 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-onlyThis ensures dependencies are installed only on the specified platforms. 🚀
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.