Python打包:wheels与tarball(tar.gz)

2024-04-25 19:29:29 发布

您现在位置:Python中文网/ 问答频道 /正文

轮子比鸡蛋的优势是显而易见的(参见“为什么不是鸡蛋”?https://pypi.python.org/pypi/wheel)。

然而,我并不完全清楚使用轮子比tar.gz有什么好处。我可能遗漏了一些显而易见的东西,比如“它们是一样的”。 如我所见,这两个程序都可以直接使用pip(甚至在Windows中)安装,具有相似的大小,并且当打包需要类似的工作时。 在我看来,这就像是你在证明包装方法时可能遇到的问题。

编辑: 刚刚发现了一个例子,其中tar.gz可能比wheels更好。CherryPy(https://pypi.python.org/pypi/CherryPy)只为Python 3.x提供控制盘,因此如果您希望有一个本地存储库来为Python 2.7和3.x依赖项提供CherryPy,那么存储tarball似乎更有意义。是这样吗?(只是在讨论中添加一些“基于案例”的理由)


Tags: piphttpsorg程序pypi证明windowstar
2条回答

来自Python Wheels

Advantages of wheels

• Faster installation for pure python and native C extension packages.
• Avoids arbitrary code execution for installation. (Avoids setup.py)
• Installation of a C extension does not require a compiler on Windows or OS X.
• Allows better caching for testing and continuous integration.
• Creates .pyc files as part of installation to ensure they match the python interpreter used.
• More consistent installs across platforms and machines.

确保车轮已安装。

pip install wheel

这给了我答案(直接从轮子上PEP):

Python needs a package format that is easier to install than sdist. Python's sdist packages are defined by and require the distutils and setuptools build systems, running arbitrary code to build-and-install, and re-compile, code just so it can be installed into a new virtualenv. This system of conflating build-install is slow, hard to maintain, and hinders innovation in both build systems and installers.

Wheel attempts to remedy these problems by providing a simpler interface between the build system and the installer. The wheel binary package format frees installers from having to know about the build system, saves time by amortizing compile time over many installations, and removes the need to install a build system in the target environment.

https://www.python.org/dev/peps/pep-0427/#rationale

注意,我们所说的tarballs是上面所说的“sdists”。

相关问题 更多 >