0

I have some code in a setup.py file that checks for a third-party SDK that must be manually installed before the application is installed:

import sys
from setuptools import setup

# ---- BEGIN SDK CHECK

try:
    import pyzed.sl
except ImportError:
    print("ERROR: You must manually install the ZED Python SDK first.")
    sys.exit(1)

zed_version = [int(p) for p in pyzed.sl.Camera.get_sdk_version().split(".")]
if zed_version < [4,0,8]:
    print("ERROR: ZED SDK 4.0.8 or higher is required, you must update the ZED SDK first.")
    sys.exit(1)

# ---- END SDK CHECK

setup(...)

However, I only want this code to execute when the package is installed, not when the package source tarball / wheel is built. That is:

  • I want it to execute when pip install ... is run.
  • I do not want it to execute when python -m build -x ... is run.

Is there some way to accomplish this? E.g. is there a way to determine if setup.py was invoked via pip install but not via python -m build? Or is there some other way to only run checks on install?

1
  • 1
    That is not really possible (any more). Maybe by jumping through a bunch of hoops, it might be possible. -- The setup.py is never in wheels, but it is in the sdist. When given a sdist, pip will typically build it into a wheel, cache the wheel, and install from the wheel. And since the wheel does not contain the setup.py, the code in setup.py is not run at install time. -- It is best to document things correctly what (system) dependencies should be pre-installed. -- Maybe the draft PEP 725, could be interesting for your use case in the future. Commented Mar 28, 2024 at 20:39

1 Answer 1

-1

Ensure that you have the python dev libraries installed that are necessary to build packages.

On debian eco system based distros like ubuntu and so on you will need to install seperatly, called "python-dev": https://packages.ubuntu.com/search?keywords=python-dev

and on RPM based systems it's called "python-devel"

https://rpmfind.net/linux/rpm2html/search.php?query=python-devel

hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.