简体   繁体   English

在 python setup.py 中,如何允许用户在不先构建的情况下安装我的模块文件?

[英]In python setup.py, how can I allow a user to install my module's files without doing a build first?

I have created a Python module that wraps some C functionality.我创建了一个包含一些 C 功能的 Python 模块。 My potential users are using MS Windows, and I'm using distutils to build the c functionality into a .pyd file.我的潜在用户正在使用 MS Windows,我正在使用 distutils 将 c 功能构建到 .pyd 文件中。

I created a manifest file which includes the .pyd file in the Python package, and everything, including the .pyd file, gets checked into version control.我创建了一个清单文件,其中包含 Python 包中的 .pyd 文件,并且所有内容(包括 .pyd 文件)都被签入版本控制。 Users then can check it out of version control and install the module.然后用户可以从版本控制中检查它并安装模块。

Most users of the module will not have the ability to rebuild the .pyd file from source code, because they don't have Visual Studio installed, and they don't necessarily have access to the libraries required to link the source code.该模块的大多数用户将无法从源代码重建 .pyd 文件,因为他们没有安装 Visual Studio,并且他们不一定有权访问链接源代码所需的库。 So I want them to be able to to use the .pyd file that I'm including in the package.所以我希望他们能够使用我包含在包中的 .pyd 文件。

The problem is when a user does python setup.py install , it sometimes tries to rebuild the .pyd file, depending on the relative timestamps of the .pyd file and the source files.问题是当用户执行python setup.py install ,它有时会尝试重建 .pyd 文件,具体取决于 .pyd 文件和源文件的相对时间戳。 I can't control which timestamp is later, I think it depends on what order they files are fetched from version control.我无法控制哪个时间戳更晚,我认为这取决于从版本控制中获取文件的顺序。

What is the correct way to handle this situation?处理这种情况的正确方法是什么?

The correct way to handle this situation is to build and distribute a wheel tagged for windows.处理这种情况的正确方法是构建和分发为窗口标记的轮子 You would do this, in addition to (or instead of) releasing a source distribution.除了(或代替)发布源代码分发之外,您还可以这样做。

pip install --upgrade setuptools wheel
python setup.py build bdist_wheel

This will generate a .whl file under ./dist/ subdirectory, which you then upload to an index (or you can send users the distribution file directly).这将在./dist/子目录下生成一个.whl文件,然后您将其上传到索引(或者您可以直接向用户发送分发文件)。

Your users will not do python setup.py install , they will do pip install yourmodule and pip will resolve the correct binary distribution ie .whl file to download and install based upon the runtime platform.您的用户不会执行python setup.py install ,他们会执行pip install yourmodule并且 pip 将解析正确的二进制分发,即.whl文件以根据运行时平台下载和安装。 Compatibility tags are present in the wheel's filename.兼容性标签存在于轮子的文件名中。

If you wish to support multiple platforms, you may need to build separate wheels tagged for different platforms.如果您希望支持多个平台,您可能需要为不同的平台构建单独的轮子。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM