Python:为什么有些包被安装为鸡蛋形式,有些则被安装为“鸡蛋文件夹”?

2024-03-28 11:59:05 发布

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

我维护了一些Python包。我有一个非常相似的setup.py文件。但是,在执行setup.py install操作时,我的一个包被安装为egg,而其他包被安装为“egg文件夹”,即扩展名为“egg”的文件夹。

导致这种不同行为的原因是什么?


Tags: install文件py文件夹eggsetup原因包被
2条回答

The Internal Structure of Python Eggs, Zip Support Metadata

If zip-safe exists, it means that the project will work properly when installed as an .egg zipfile, and conversely the existence of not-zip-safe means the project should not be installed as an .egg file [ie. as an .egg directory]. The zip_safe option to setuptools' setup() determines which file will be written. If the option isn't provided, setuptools attempts to make its own assessment of whether the package can work, based on code and content analysis.

一个egg文件实际上是一个zip归档文件,里面有一个特定的目录结构。根据zipimport文档,只能从zip文件导入.py.pyc.pyo文件。因此,如果包需要导入其他类型的模块资源(比如编译的c代码;.so文件,.pyd文件),它就不能作为zip文件工作。

我不知道这是否是一些鸡蛋不能用作压缩文件的唯一原因,但我认为这是主要原因。

相关问题 更多 >