admin管理员组

文章数量:1332361

I have several python packages that need to be installed on various os/environments. These packages have dependencies and some of them like Polars needs a different package depending on the OS, for example: polars-lts-cpu on MacOS (Darwin) and polars on all the other OS.

I use setuptools to create a whl file, but the dependencies installed depend on the OS where the wheel file was created. Here is my code:

import platform
from setuptools import find_packages, setup

setup(
    ...
    install_requires=["glob2>=0.7",
                       "numpy>=1.26.4",
                       "polars>=1.12.0" if platform.system() != "Darwin" else "polars-lts-cpu>=1.12.0"]
    ...)

As mentioned above, this code installs the version of Polars according to the OS where the wheel file was created, not according to where the package will be installed.

How can I fix this?

I have several python packages that need to be installed on various os/environments. These packages have dependencies and some of them like Polars needs a different package depending on the OS, for example: polars-lts-cpu on MacOS (Darwin) and polars on all the other OS.

I use setuptools to create a whl file, but the dependencies installed depend on the OS where the wheel file was created. Here is my code:

import platform
from setuptools import find_packages, setup

setup(
    ...
    install_requires=["glob2>=0.7",
                       "numpy>=1.26.4",
                       "polars>=1.12.0" if platform.system() != "Darwin" else "polars-lts-cpu>=1.12.0"]
    ...)

As mentioned above, this code installs the version of Polars according to the OS where the wheel file was created, not according to where the package will be installed.

How can I fix this?

Share Improve this question asked Nov 21, 2024 at 1:46 FiReTiTiFiReTiTi 5,89813 gold badges34 silver badges62 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

Use declarative environment markers as described in PEP 496 and PEP 508:

   install_requires=[
      "polars>=1.12.0; platform_system!='Darwin'",
      "polars-lts-cpu>=1.12.0; platform_system=='Darwin'",
   ]

本文标签: pythonBuild a wheel and Install package version depending on OSStack Overflow