如何避免用我的python包构建C库? [英] How to avoid building C library with my python package?

查看:148
本文介绍了如何避免用我的python包构建C库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C库与ctypes构建一个python包。
我想让我的包可移植(Windows,Mac和Linux)。

I'm building a python package using a C library with ctypes. I want to make my package portable (Windows, Mac and Linux).

我发现了一个策略,使用 build_ext pip 在我的软件包安装过程中构建库。它创建 libfoo.dll libfoo.dylib libfoo.so

I found a strategy, using build_ext with pip to build the library during the installation of my package. It creates libfoo.dll or libfoo.dylib or libfoo.so depending on the target's platform.

这个问题是我的用户需要CMake安装。

The problem with this is that my user needs CMake installed.

是否存在避免在安装过程中构建的另一个策略?

Does exist another strategy to avoid building during the installation? Do I have to bundle built libraries in my package?

我想让我的用户做 pip install mylib

编辑:感谢@Dawid评论,我试图创建一个 python wheel 使用命令 python setup.py bdist_wheel 无任何成功。

Edit: thank to @Dawid comment, I'm trying to make a python wheel with the command python setup.py bdist_wheel without any success.

如何创建

编辑2:我使用的是python 3.4,并在Mac操作系统X,但我可以访问Windows计算机和Linux计算机

Edit 2: I'm using python 3.4 and working on Mac OS X, but I have access to Windows computer, and Linux computer

推荐答案

研究...正如丹尼尔所说,你唯一的选择是自己构建和分发二进制文件。

You're certainly heading down the right path according to my research... As Daniel says, the only option you have is to build and distribute the binaries yourself.

一般来说,推荐的安装包的方法很好打包用户指南。我不会重复那里的建议,因为你已经明确已经找到它。然而,关键在于Python社区,特别是 PyPA 正在尝试标准化使用平台轮可打包二进制扩展。很遗憾,此时有几个问题:

In general, the recommended way to install packages is covered well in the packaging user guide. I won't repeat advice there as you have clearly already found it. However the key point in there is that the Python community, specifically PyPA are trying to standardize on using platform wheels to package binary extensions. Sadly, there are a few issues at this point:


  1. 如上面的链接所述,您无法将Linux轮盘上传到PyPI,您必须自行管理发布给您的用户。

  2. 关于构建扩展程序的建议有些不完整,反映了缺少一个完整的二进制分布解决方案。

  3. 然后,人们尝试构建自己的库并将其作为数据文件分发,这会混淆setuptools。

  1. As mentioned in the above link, you cannot upload Linux wheels to PyPI, which means you have to manage the distribution to your users yourself.
  2. The advice on building extensions is somewhat incomplete, reflecting the lack of a complete solution for binary distributions.
  3. People then try to build their own library and distribute it as a data file, which confuses setuptools.

我想你碰到了最后一个问题。 解决方法是强制分发人员构建平台轮通过重写is_pure()始终返回False。但是,你可以只保留你原来的构建指令,而bdist_wheel应该处理它。

I think you are hitting this last issue. A workaround is to force the Distribution to build a platform wheel by overriding is_pure() to always return False. However you could just keep your original build instructions and bdist_wheel should handle it.

一旦你建立了轮,但是,你仍然需要分发它,包使用或使用它。此时,您可能需要使用推荐的工具喜欢conda或像 devpi 这样的PyPI代理服务您的车轮。

Once you've built the wheel, though, you still need to distribute it and maybe other binary packages that it uses or use it. At this point, you probably need to use one of the recommended tools like conda or a PyPI proxy like devpi to serve up your wheels.

编辑:回答有关交叉编译的额外问题

https://docs.python.org/2/distutils/builtdist.html#cross-compiling-on-windowsrel =nofollow> here Python 2.6和更高版本允许对Windows 32/64进行交叉编译位构建。没有对其他平台上的其他软件包的正式支持,人们已经有限的成功试图做它。你真的最好在每个Linux / Mac / Windows环境中自然构建。

As covered here Python 2.6 and later allows cross-compilation for Windows 32/64-bit builds. There is no formal support for other packages on other platforms and people have had limited success trying to do it. You are really best off building natively on each of your Linux/Mac/Windows environments.

这篇关于如何避免用我的python包构建C库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆