什么是Python蛋?
我试图了解 Python 包是如何工作的。大概eggs
是某种包装机制,但是如何快速概述它们所扮演的角色以及它们为何有用以及如何创建它们的一些信息呢?
I'm trying to understand how Python packages work. Presumably eggs
are some sort of packaging mechanism, but what would be a quick overview of what role they play and may be some information on why they're useful and how to create them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
与Java中的
.jar
文件概念相同,它是一个.zip
文件,其中一些元数据文件重命名为.egg
,用于分发代码作为捆绑。具体来说:Python Eggs 的内部结构
Same concept as a
.jar
file in Java, it is a.zip
file with some metadata files renamed.egg
, for distributing code as bundles.Specifically: The Internal Structure of Python Eggs
.egg
文件是 Python 包的分发格式。它只是源代码分发或 Windowsexe
的替代方案。但请注意,对于纯Python
,.egg
文件是完全跨平台的。.egg
文件本身本质上是一个.zip
文件。如果将扩展名更改为“zip
”,您可以看到存档内会有文件夹。另外,如果您有
.egg
文件,则可以使用easy_install
将其安装为包,示例:
要为
mymath
目录创建.egg
文件,该目录本身可能有多个 python 脚本,请执行以下步骤:然后,从终端执行:
这将生成大量输出,但完成后您会看到有三个个新文件夹:build、dist和mymath.egg-信息。我们唯一关心的文件夹是 dist 文件夹,您可以在其中找到
.egg
文件,mymath-0.1-py3.5.egg
使用默认的Python(安装)版本号(我的版本号:3.5)来源:Python图书馆博客
The
.egg
file is a distribution format for Python packages. It’s just an alternative to a source code distribution or Windowsexe
. But note that for purePython
, the.egg
file is completely cross-platform.The
.egg
file itself is essentially a.zip
file. If you change the extension to “zip
”, you can see that it will have folders inside the archive.Also, if you have an
.egg
file, you can install it as a package usingeasy_install
Example:
To create an
.egg
file for a directory saymymath
which itself may have several python scripts, do the following step:Then, from the terminal do:
This will generate lot of outputs, but when it’s completed you’ll see that you have three new folders: build, dist, and mymath.egg-info. The only folder that we care about is the dist folder where you'll find your
.egg
file,mymath-0.1-py3.5.egg
with your default python (installation) version number(mine here: 3.5)Source: Python library blog
免责声明:egg 是一种废弃的 python 包格式,使用 Eggs 的工具已不复存在。
Egg 是一个 python 包。它是一个包含 python 源文件和/或编译库的 zip 存档。
该格式没有明确规定它必须包含什么内容或如何为不同版本的 python 和不同操作系统制作包,这是它被替换的原因之一。
该格式于 2004 年左右出现,一直使用到 2010 年代中期,已完全被
wheels
和pip install
取代。Egg 是通过命令
easy_install
安装的。该命令已在 setuptools v58.3(2021 年)中删除。您不能再使用鸡蛋。如果您看到任何提及
easy_install
或egg
的内容,无论是任何堆栈溢出答案还是教程,它都已经严重过时了。推荐这个较长的答案 https://stackoverflow.com/a/68897551/5994461 以深入了解 python 打包的历史。它涉及点、轮子、鸡蛋等等。
更新:截至 2023 年 7 月,官方 python 包存储库 pypi.org 不再接受.egg包上传。
Disclaimer: egg is an abandoned format of python package, the tools to use eggs no longer exist.
An egg is a python package. It's a zip archive containing python source files and/or compiled libraries.
The format is not well specified about what it must contain or how to make packages for different versions of python and different operating systems, that's one of the reasons it was replaced.
The format appeared around 2004 and was in-use until the mid 2010s, it's been completely replaced by
wheels
andpip install
.Eggs were installed by the command
easy_install
. The command was removed in setuptools v58.3 (year 2021). You can no longer use eggs.If you see anything that mentions
easy_install
oregg
, be it any stack overflow answers or tutorials, it is seriously obsolete.Recommend this longer answer https://stackoverflow.com/a/68897551/5994461 for an in-depth history of python packaging. It's going over pip and wheels and eggs and much more.
Update: As of July 2023 the official python package repository pypi.org no longer accepts upload of .egg packages.
“Egg”是 Python 相关项目的单文件可导入分发格式。
“Python Egg 快速指南” 指出“Eggs 对于 Python 就像 Jars 一样”到 Java...”
鸡蛋其实比罐子更丰富;它们保存有趣的元数据,例如许可详细信息、版本依赖项等。
"Egg" is a single-file importable distribution format for Python-related projects.
"The Quick Guide to Python Eggs" notes that "Eggs are to Pythons as Jars are to Java..."
Eggs actually are richer than jars; they hold interesting metadata such as licensing details, release dependencies, etc.