setup.py 代码在 `pip install` 上运行,但不在 `python -m build` 上运行

问题描述 投票:0回答:1

我在 setup.py 文件中有一些代码,用于检查在安装应用程序之前必须手动安装的第三方 SDK:

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(...)

但是,我只希望在安装包时执行此代码,而不是在构建包源 tarball/wheel 时执行。那就是:

我希望它在
    pip install ...
  • 运行时执行。
    我不希望它在 
  • python -m build -x ...
  • 运行时执行。
    
    
  • 有什么办法可以做到这一点吗?例如。有没有办法确定
setup.py

是否通过 pip install 调用而不是通过

python -m build
调用?或者有其他方法只在安装时运行检查吗?
    

python pip setup.py python-packaging
1个回答
0
投票

在基于 debian 生态系统的发行版(如 ubuntu 等)上,您需要单独安装,称为“python-dev”:

https://packages.ubuntu.com/search?keywords=python-dev

在基于 RPM 的系统上它被称为“python-devel”

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

希望有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.