简体   繁体   English

如何创建特定于平台的Python包?

[英]How can I make a Python package that is platform-specific?

I have a Python package that can only meaningfully run on Linux. 我有一个只能在Linux上有意义地运行的Python包。 I've seen in the docs that there is a platforms key in the setup.py metadata, but as far as I can tell from poking around in the distutils source, this metadata isn't actually used for anything. 我在文档中看到setup.py元数据中有一个platforms键,但据我所知,在distutils源代码中,这个元数据实际上并没有用于任何事情。

Next, I went and looked at PyObjC, a prominent OS X-only Python package. 接下来,我去看了PyObjC,一个着名的OS X-only Python包。 I observe that it populates the aforementioned platforms key in its setup.py . 我观察到它在setup.py填充了前面提到的platforms键。 However, when I try to install PyObjC on Linux, the installation isn't prevented or blocked in any intentional way. 但是,当我尝试在Linux上安装PyObjC时,不会以任何有意的方式阻止或阻止安装。 The failure mode that ensues is pretty ungraceful: it errors out when platform.mac_ver() returns a value it doesn't expect. 接下来的失败模式非常糟糕:当platform.mac_ver()返回它不期望的值时,它会出错。 I tried manually fixing that problem, and distutils appeared to be going about its merry way collecting dependencies, etc. until eventually it failed looking for a platform specific file... Bottom line, distutils is not handling platform-specific packages in any reasonable way. 我尝试手动修复这个问题,并且distutils似乎正在以其快乐的方式收集依赖关系等等,直到最终它找不到特定于平台的文件...底线, distutils没有以任何合理的方式处理特定于平台的包。

Ideally, I would expect the installation to fail with some message indicating that the package is not compatible with the current platform. 理想情况下,我希望安装失败,并显示一些消息,指出该软件包与当前平台不兼容。 I've noodled around a bit and the "best" thing I've been able to come up with involves subclassing the install and develop commands and handling a platform check manually there. 我已经涂了一点,我能够提出的“最好”的东西包括子类化installdevelop命令并在那里手动处理平台检查。

Is there a better way? 有没有更好的办法?

I am probably oversimplifying, but at the top of your setup.py couldn't you just do something like: 我可能过于简单了,但在你的setup.py的顶部,你不能只做以下事情:

import platform
distname,version,id = platform.linux_distribution()
if not distname:
   raise Exception('Aborting installation: Requires Linux')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 诗歌:如何指定特定于平台的依赖项替代方案? - Python Poetry: how to specify platform-specific dependency alternatives? 如何使用构建工具创建平台特定的 Python wheel? - How to create platform-specific Python wheel with build tool? 字节编译是否特定于Python平台? - Is byte-compiling Python platform-specific? 如何提供模块的特定于平台的实现? - How to offer platform-specific implementations of a module? 如何分发和执行特定于平台的单元测试? - How to distribute and execute platform-specific unit tests? 通过PIP安装特定于平台的依赖项 - Installing platform-specific dependencies through PIP 在Windows中无人值守安装具有特定于平台的扩展的Python软件包的常用方法是什么? - What is the usual method for unattended installation of Python packages with platform-specific extensions in Windows? 我如何才能将Python virtualenv用于其他平台? - How can I make a Python virtualenv meant for another platform? 有没有办法在environment.yml中具有特定于平台的依赖项? - Is there a way to have platform-specific dependencies in environment.yml? 是否可以在 setup.py 中表达特定于平台的依赖项而无需构建特定于平台的版本我的蛋? - Is it possible to express a platform-specific dependency in setup.py without building platform-specific versions of my egg?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM