简体   繁体   中英

setup.py how to specify that I depend on optional dependency?

Specifically, I want to use pywebview , which must be installed with either pywebview[gtk3] or pywebview[qt5] and so on.

It doesn't make sense to use this project without any of these dependencies (you absolutely must have one that matches your platform), but for some reason they are optional, so aren't installed by default.

I cannot find the correct syntax to specify these dependencies in my setup.py .


This is something I tried:

install_requires=[
    ...
    'pywebview >= 2.0.3',
    'pywebview[qt5];platform_system=="Linux"',
    'pywebview[winforms];platform_system=="Windows"',
    'pywebview[cocoa];platform_system=="Darwin"',
    'vext >= 0.7.0',
    'vext.gi >= 0.7.0',
]

But I have no way of verifying whether this will work. There's zero documentation on possible values of platform_system .

You can use platform specific dependancies:

#!/usr/bin/env python
from setuptools import setup

setup(
    name='spam',
    version='0.0.1',
    extras_require={
        ':sys_platform == "win32"': [
            'qt5'
        ],
        ':"linux" in sys_platform': [
            'gtk3'
        ]
    },
    install_requires=[
        'pywebview'
        ],
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM