Python: Why do some packages get installed as eggs and some as "egg folders"?
Asked Answered
C

2

28

I maintain a few Python packages. I have a very similar setup.py file for each of them. However, when doing setup.py install, one of my packages gets installed as an egg, while the others get installed as "egg folders", i.e. folders with an extension of "egg".

What is the difference between them that causes this different behavior?

Control answered 9/5, 2010 at 17:9 Comment(0)
D
29

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.

Donahue answered 9/5, 2010 at 17:29 Comment(4)
What makes a project zip-safe? Why would you choose one or the other? (I ask as someone packaging a project.)Emblaze
From setuptools documentation: peak.telecommunity.com/DevCenter/…Saltish
saffsd's link would be setuptools.readthedocs.io/en/latest/… nowDonahue
10 years later, @saffsd's link now would be setuptools.pypa.io/en/latest/deprecated/zip_safe.html (including "this flag is considered obsolete")Donahue
P
5

A single egg file is in fact a zip archive with a particular directory structure inside. Per the zipimport documentation, only .py, .pyc, and .pyo files can be imported from zip files. So, if the package needs to import other kinds of module resources (like compiled c code; .so files, .pyd files) it won't work as a zip file.

I don't know if this is the only reason that some eggs won't work as zip archives, but I think it is the main reason.

Photoreceptor answered 9/5, 2010 at 17:43 Comment(1)
It's not the main reason. It's not even a correct reason. setuptools adds special loaders to make .so and .pyd files work even with a compressed egg. The other answer is the correct one.Cambrel

© 2022 - 2024 — McMap. All rights reserved.