Python 包和 egg-info 目录

有人能解释一下 egg-info 目录是如何绑定到它们各自的模块的吗:

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

我假设 egg-info 目录使相应的模块对 setuptools (easy _ install)可见,对吗?如果是这样,setuptools 如何将 egg-info 目录绑定到模块目录?

假设我的思路是正确的,举个例子... ... 如果我想让 setuptools 可以看到我的现有包,我可以只是用符号链接模块目录和 egg-info 目录到 site-package 目录吗?我本来可以自己尝试一下,但是我不确定如何测试这个包对 setuptools 是否可见。如果你也能告诉我如何测试这个,那么加分:)

我试图理解这一切的主要原因是因为我想将我的一些模块符号化为站点包,这样我就可以对它们进行更改,并且使用它们的脚本可以看到更改,而不必在每次更改后从 PyPI 重新安装 egg。

65369 次浏览

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.