Python 包和 egg-info 目录 [英] Python packages and egg-info directories

查看:108
本文介绍了Python 包和 egg-info 目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释一下 egg-info 目录是如何与它们各自的模块相关联的吗?例如,我有以下内容:

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/

我假设 egg-info 目录是为了使相应的模块对 setuptools (easy_install) 可见,对吗?如果是这样,setuptools 如何将 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?

假设我在正确的轨道上,并且为了示例......如果我想让我的现有包对 setuptools 可见,我可以将模块目录和 egg-info 目录符号链接到站点包目录?我自己会尝试这个,但我不确定如何测试该包是否对 setuptools 可见.如果你能告诉我如何测试这个,那就加分吧:)

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 :)

我试图理解这一切的主要原因是因为我想将我的一些模块符号链接到站点包中,以便我可以对它们进行更改并使使用它们的脚本可以看到更改而无需每次更改后从 PyPI 重新安装鸡蛋.

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.

推荐答案

只有在使用 --single-version-externally-managed 安装 egg 时,才会创建 .egg-info 目录.通常",安装一个 egg 会创建一个单独的目录(或 zip 文件),其中包含代码和元数据.

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(读取元数据的库)有一个函数 require 可用于请求包的特定版本.对于旧式"的常规导入,easy_install 破解了一个 .pth 文件以将 egg 目录放到 sys.path 上.对于--single-version-externally-managed,这种黑客攻击是没有必要的,因为只会安装一个版本(通过系统的打包基础设施,例如rpm或dpkg).对于使用 require(或任何其他 pkg_resources 绑定机制)的应用程序,仍包含 egg-info.

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).

如果你想通过硬链接安装一个包,我推荐使用setup.py develop".这是来自 setuptools 的一个命令,它实际上并没有安装鸡蛋,而是让它在整个站点范围内可用.为此,它创建了一个 egg-link 文件,以便 pkg_resources 可以找到它,并操作一个 .pth 文件,以便常规导入可以找到它.

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.

这篇关于Python 包和 egg-info 目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆