Is it possible to express a platform-specific dependency in setup.py without building platform-specific versions of my egg?

Daniel Fortunov picture Daniel Fortunov · Jun 24, 2011 · Viewed 8.8k times · Source

We have a placeholder egg that contains no code and only exists for the sake of pulling down a list of dependent packages from our PyPi repository.

Most of these dependent packages are platform-agnostic, however some are only used on Win32 platforms.

Is it possible to somehow make the dependency platform-conditional, so that a given dependency in my install_requires list will only get pulled down when installing on Win32?

Alternatively: Is it possible to specify a list of optional dependencies, that will be installed if available, but will not cause easy_install to fail if they are not?

Answer

wtayyeb picture wtayyeb · Mar 22, 2017

For sdist, egg and wheel release from : http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies

Sometimes a project might require a dependency to run on a specific platform. This could to a package that back ports a module so that it can be used in older python versions. Or it could be a package that is required to run on a specific operating system. This will allow a project to work on multiple different platforms without installing dependencies that are not required for a platform that is installing the project.

setup(
    name="Project",
    ...
    install_requires=[
        'enum34 ; python_version<"3.4"',
        'pywin32 >= 1.0 ; platform_system=="Windows"'
    ]
)