Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python packages and egg-info directories

Can someone explain how egg-info directories are tied to their respective modules? For example, I have the following:

/usr/local/lib/python2.5/site-packages/quodlibet/ /usr/local/lib/python2.5/site-packages/quodlibet-2.0.egg-info/ 

I'm assuming the egg-info directory is to make the corresponding module visible to setuptools (easy_install), right? If so, how does setuptools tie the egg-info directory to the module directory?

Assuming that I'm on the right track, and for the sake of example... If I wanted to make an existing package of mine visible to setuptools, could I just symlink the module directory and the egg-info directory to the site-packages directory? I would have just tried this myself, but I'm not sure how to test if the package is visible to setuptools. Bonus points if you can also tell me how to test this :)

The main reason I'm trying to understand all this is because I would like to symlink some of my modules into site-packages so that I can make changes to them and have the changes visible to the scripts that use them without having to reinstall the egg from PyPI after each change.

like image 766
Jeremy Cantrell Avatar asked Nov 02 '08 02:11

Jeremy Cantrell


People also ask

What are egg info directories?

egg-info format: a file or directory placed adjacent to the project's code and resources, that directly contains the project's metadata.

What is python eggs folder?

The . egg file is a distribution format for Python packages. It's just an alternative to a source code distribution or Windows exe .

What is python Dist info?

dist-info : a directory of files containing information about the package, such as a metadata file with information such as the package's author and what versions of Python it supports (METADATA), a license file (LICENSE), a file specifying what tool was used to install the package (INSTALLER), and more.


1 Answers

The .egg-info directories get only created if --single-version-externally-managed was used to install the egg. "Normally", installing an egg would create a single directory (or zip file), containing both the code and the metadata.

pkg_resources (which is the library that reads the metadata) has a function require which can be used to request a specific version of the package. For "old-style", regular imports, easy_install hacks a .pth file to get the egg directory onto sys.path. For --single-version-externally-managed, this hacking is not necessary, because there will only be a single version installed (by the system's pacakging infrastructure, e.g. rpm or dpkg). The egg-info is still included, for applications that use require (or any of the other pkg_resources binding mechanisms).

If you want to install a package by hard-linking, I recommend to use "setup.py develop". This is a command from setuptools which doesn't actually install the egg, but makes it available site-wide. To do so, it creates an egg-link file so that pkg_resources can find it, and it manipulates a .pth file, so that regular import can find it.

like image 82
Martin v. Löwis Avatar answered Sep 24 '22 00:09

Martin v. Löwis