python:easy_install 期间会发生什么?

发布于 2024-11-25 22:27:29 字数 752 浏览 6 评论 0原文

我对 Egg 文件和使用 easy_install 安装它们有点困惑,希望你能帮助我。 (我读到了人们对 pip 的推荐,但在继续之前我想了解这一点)。

如果我只是从拇指驱动器复制例如 django_guardian-1.0.2-py2.6.egg 并将其放置在 PYTHONPATH 指向的例如 ~/bar/ 中,尝试通过 import Guardian 导入内容会产生 importError。即使我现在复制了 easy_install.pth 也会出现此错误

import sys; sys.__plen = len(sys.path)
./django_guardian-1.0.2-py2.6.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys
'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)

,使用 easy_install django-guardian 当然没有这样的问题。

我导航到了 egg 文件 easy_installed 所在的目录,它包含的只是 .pth.egg 文件。我想知道 easy_install 在某个地方做了哪些其他过程/条目,导致第一种方法无法使用......

I'm a little confused about egg files and installing them using easy_install, hope you can help me with it. (I read about people's recommendation on pip, but I'll like to understand this before I move on).

If I simply copy e,g django_guardian-1.0.2-py2.6.egg from say, a thumbdrive and place in e.g ~/bar/ which PYTHONPATH was pointing to, trying to import the contents via import guardian would yield me importError. This error occur even if I have the easy_install.pth copied in

import sys; sys.__plen = len(sys.path)
./django_guardian-1.0.2-py2.6.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys
'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)

Now, using easy_install django-guardian, of course had no such problem.

I navigated to the directory the egg file was easy_installed to, and all it contains was the .pth and the .egg file. I wish to know what other procedures/entries does easy_install makes somewhere that makes the first method unusable....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回梦 2024-12-02 22:27:29

easy_install 使用 .pth 文件将 .egg 文件添加到 sys.path - 位置列表Python 搜索要导入的模块。

.pth 文件由 site 模块处理,但仅在四个预定义的目录中。这些目录是特定于平台的,并且基于 sys.prefix 和 sys.exec_prefix 设置。在 Unix 上,最突出的通常是 /usr/lib/pythonXX/site-packages

由于您的自定义目录不是 site 处理的目录之一,因此您的 .pth 文件不会得到处理,Python 也不会查看 .egg 内部

有关详细信息,请参阅site 模块文档

easy_install uses .pth files to add the .egg files to sys.path -- the list of locations where Python searches for modules to import.

.pth files are processed by the site module, but only in four pre-defined directories. These directories are platform-specific and based on the sys.prefix and sys.exec_prefix settings. On Unix, the most prominent usually is /usr/lib/pythonXX/site-packages.

Since your custom directory is not one of the directories processed by site, your .pth file won't get processed and Python won't look inside the .egg.

For more information, see the site module documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文