I want to add pywin32 as Conditional Python Dependencies to setup.py when platform_system == Windows
Could anyone give me a hint on how to make it work?
After exploring the stackoverflow, haven't found a answer to python2.7.
I'm using Python 2.7, setuptools 28.x.x, pip 19.x.x. Egg-info is auto-build.
from setuptools import setup, find_packages
import platform
platform_system = platform.system()
setup(
name=xxx,
version=xxx,
packages=find_packages(),
include_package_data=True,
install_requires=[
'matplotlib',
],
extras_require={
'platform_system=="Windows"': [
'pywin32'
]
},
entry_points='''
[console_scripts]
xx:xx
''',
)
I don't understand how the keys in extras_require work. Would platform_system refer to the definition of platform_system in the front?
I also tried:
from setuptools import setup, find_packages
import platform
setup(
xxx
install_requires=[
'matplotlib',
'pywin32;platform_system=="Windows"',
],
)
But this is available only for python_version>=3.4
Also, it looks like https://www.python.org/dev/peps/pep-0508/ doesn't work for me.
You can use Environment Markers in the specification of your dependencies. See PEP 508.
For detecting if the operating system is Windows or not, you can use os_name being equal to nt.
Based on the syntax in the PEP which shows "name; os_name=='a' or os_name=='b'", your install_requires section can be:
install_requires=[
"matplotlib",
"pywin32; os_name=='nt'",
],
There is no need to use extras_require for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With