1

I'm trying to exclude a specific library from being installed whenever users install my package via pip while not on macOS

Here's my logic:

if platform.system() == "Darwin":
    install_packages = setuptools.find_packages()
else:
    install_packages = setuptools.find_packages(exclude=["appscript==1.2.0"])

Then in setuptools.setup I use: packages=install_packages

This doesn't seem to work..

Building wheels for collected packages: appscript
  Building wheel for appscript (setup.py) ... error

How do I exclude this package from my setup? I'm new to this, so I'm sure I missed something.

Thanks!

sinoroc
  • 18,409
  • 2
  • 39
  • 70
TheCrazySwede
  • 113
  • 2
  • 10
  • Use environment markers: [_PEP 508_](https://peps.python.org/pep-0508/#environment-markers). Something like `appscript==1.2.0 ; platform_system=="Darwin"` in your `install_requires`. Consider also moving to `pyproject.toml`, to avoid writing such dynamic code-based logic in `setup.py` which is very much discouraged nowadays; in favor of static descriptive configuration files (`pyproject.toml` or `setup.cfg`). – sinoroc Aug 13 '22 at 08:40
  • https://stackoverflow.com/a/49501010/11138259 – sinoroc Aug 13 '22 at 08:45

1 Answers1

-1

If anyone else stumbles upon this looking for an easy fix, here's what I did

from pip._internal import main as pip

if platform.system() == "Darwin":
    pip(['install', '--user', 'appscript==1.2.0'])

Windows still throws an error when doing a pip install, but if I run it a second time it installed it just fine without any issues.

TheCrazySwede
  • 113
  • 2
  • 10
  • This is very bad practice. This will break sooner or later. And it is entirely unnecessary. -- Use PEP 508 environment markers, this is the way to go and will work reliably and will be compatible with the whole Python packaging ecosystem. – sinoroc Aug 15 '22 at 21:39