python - PyPI 上上传的 Python 库的分发格式
问题描述
我完成了将包上传到https://test.pypi.org/的教程,我成功地这样做了。
但是,会在目录中$python setup.py sdist bdist_wheel
生成一个.whl
文件和一个tar.gz
文件dist/
。twine
允许仅上传.whl
或tar.gz
文件或两者。我在https://pypi.org/上看到许多存储库都上传了这两种格式。
我想了解什么是最佳做法。一种格式是否优于另一种格式?如果.whl
文件足以分发我的代码,我是否tar.gz
也应该上传文件?或者还有什么我在这里完全想念的。
解决方案
Best practice is to provide both.
A "built distribution" (.whl
) for users that are able to use that distribution. This saves install time as a "built distribution" is pre-built and can just be dropped into place on the users machine, without any compilation step or without executing setup.py
. There may be more than one built distribution for a given release -- once you start including compiled binaries with your distribution, they become platform-specific (see https://pypi.org/project/tensorflow/#files for example)
A "source distribution" (.tar.gz
) is essentially a fallback for any user that cannot use your built distribution(s). Source distributions are not "built" meaning they may require compilation to install. At the minimum, they require executing a build-backend (for most projects, this is invoking setup.py
with setuptools
as the build-backend). Any installer should be able to install from source. In addition, a source distribution makes it easier for users who want to audit your source code (although this is possible with built distributions as well).
For the majority of Python projects, turning a "source distribution" into a "built distribution" results in a single pure-Python wheel (which is indicated by the none-any
in a filename like projectname-1.2.3-py2.py3-none-any.whl
). There's not much difference between this and the source distribution, but it's still best practice to upload both.
推荐阅读
- jquery - 触摸事件在带有电话链接的 IOS 上不起作用
- javascript - 正则表达式不能在 FireFox 中工作,如何使这个正则表达式在 FireFox 中工作?
- static-analysis - clang-tidy 或 cppcheck 等工具与 klocwork 相比如何?
- java - 将图标与按钮左侧的文本对齐
- reactjs - 如何在日期选择器输入上显示占位符?
- c# - 如何使用 JSON 数组中的相同键连接值
- reactjs - 上下文中 useReducer 的挂钩调用无效
- c# - 以配置提供程序为目标
- tableau-api - Tableau 在 UNC 路径中用斜杠替换反斜杠
- regex - GA 正则表达式过滤器 - 过滤 PPC 流量并将其替换为“PPC”