“sdist” 和 “sdist” 和有什么不一样? .tar.gz 发行版和 python 蛋?
我有点困惑。似乎有两种不同类型的 Python 包,源代码发行版 (setup.py sdist) 和 Egg 发行版 (setup.py bdist_egg)。
两者似乎只是具有相同数据(Python 源文件)的档案。一个区别是,最推荐的包管理器 pip
无法安装 Egg。
两者之间有什么区别?分发包裹的“方式”是什么?
(注意,我不想通过 PyPI 分发我的包,但我想使用包管理器从 PyPI 获取我的依赖项)
I am a bit confused. There seem to be two different kind of Python packages, source distributions (setup.py sdist) and egg distributions (setup.py bdist_egg).
Both seem to be just archives with the same data, the python source files. One difference is that pip
, the most recommended package manager, is not able to install eggs.
What is the difference between the two and what is 'the' way to do distribute my packages?
(Note, I am not wanting to distribute my packages through PyPI, but I want to use a package manager that fetches my dependencies from PyPI)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
setup.py sdist
创建一个源代码分发:它包含 setup.py、模块/脚本的源文件(.py 文件或二进制模块的 .c/.cpp )、您的数据文件等。结果是一个存档,然后可用于在任何平台上重新编译所有内容。setup.py bdist
(和bdist_*
)创建一个内置发行版:它包括 .pyc 文件、.so/.dll/.dylib二进制模块,.exe(如果在 Windows 上使用 py2exe),您的数据文件...但没有 setup.py。结果是一个特定于平台(例如linux-x86_64
)和Python版本的存档,只需将其解压到文件系统的根目录即可安装(可执行文件是在 /usr/bin (或等效文件)中,数据文件在 /usr/share 中,模块在 /usr/lib/pythonX.X/site-packages/... 中)。您甚至可以构建可以使用包管理器直接安装的 rpm 存档。setup.py sdist
creates a source distribution: it contains setup.py, the source files of your module/script (.py files or .c/.cpp for binary modules), your data files, etc. The result is an archive that can then be used to recompile everything on any platform.setup.py bdist
(andbdist_*
) creates a built distribution: it includes .pyc files, .so/.dll/.dylib for binary modules, .exe if usingpy2exe
on Windows, your data files... but no setup.py. The result is an archive that is specific to a platform (for examplelinux-x86_64
) and to a version of Python, and that can be installed simply by extracting it into the root of your filesystem (executables are in /usr/bin (or equivalent), data files in /usr/share, modules in /usr/lib/pythonX.X/site-packages/...). You can even build rpm archives that can be directly installed using your package manager.2021 更新:Python 中不再存在构建和使用 Egg 的工具。
有两种以上不同类型的 Python(发行版)包。该命令列出了许多子命令:
注意各种不同的 bdist 类型。
Egg 是一种新的包类型,由 setuptools 引入,但后来被标准库采用。它应该整体安装到 sys.path 上。这与 sdist 包不同,后者意味着运行
setup.py install
,将每个文件复制到位,并且可能还执行其他操作(构建扩展模块、运行额外的操作)包中包含任意 Python 代码)。此时鸡蛋基本上已经过时了。编辑:鸡蛋不见了,它们与已从Python中删除的命令“easy_install”一起使用。
现在最受欢迎的打包格式是“wheel”格式,特别是“pip install”使用的格式。
无论您创建 sdist 还是 Egg(或 Wheel),都与您是否能够声明该包具有哪些依赖项(由 PyPI 在安装时自动下载)无关。要使此依赖项功能发挥作用,您只需使用 distribute (setuptools 的后继者)或 distutils2 (distutils 的后继者)提供的额外 API 来声明依赖项- 在当前的 Python 3.x 开发版本中也称为打包)。
https://packaging.python.org/ 是有关打包的更多信息的良好资源。它涵盖了声明依赖项的一些细节(例如 install_requires 但不是
extras_require
afaict)。2021 update: the tools to build and use eggs no longer exist in Python.
There are many more than two different kind of Python (distribution) packages. This command lists many subcommands:
Notice the various different bdist types.
An egg was a new package type, introduced by setuptools but later adopted by the standard library. It is meant to be installed monolithic onto
sys.path
. This differs from an sdist package which is meant to havesetup.py install
run, copying each file into place and perhaps taking other actions as well (building extension modules, running additional arbitrary Python code included in the package).eggs are largely obsolete at this point in time. EDIT: eggs are gone, they were used with the command "easy_install" that's been removed from Python.
The favored packaging format now is the "wheel" format, notably used by "pip install".
Whether you create an sdist or an egg (or wheel) is independent of whether you'll be able to declare what dependencies the package has (to be downloaded automatically at installation time by PyPI). All that's necessary for this dependency feature to work is for you to declare the dependencies using the extra APIs provided by distribute (the successor of setuptools) or distutils2 (the successor of distutils - otherwise known as packaging in the current development version of Python 3.x).
https://packaging.python.org/ is a good resource for further information about packaging. It covers some of the specifics of declaring dependencies (eg install_requires but not
extras_require
afaict).