[英]python: what happens during easy_install?
I'm a little confused about egg files and installing them using easy_install, hope you can help me with it. 我对egg文件有点困惑,并使用easy_install安装它们,希望你能帮助我。 (I read about people's recommendation on pip, but I'll like to understand this before I move on). (我读到人们对pip的推荐,但我想在继续之前理解这一点)。
If I simply copy e,g django_guardian-1.0.2-py2.6.egg
from say, a thumbdrive and place in eg ~/bar/
which PYTHONPATH was pointing to, trying to import the contents via import guardian
would yield me importError. 如果我简单地复制e,g django_guardian-1.0.2-py2.6.egg
,例如,一个django_guardian-1.0.2-py2.6.egg
并放置在例如~/bar/
PYTHONPATH指向的地方,尝试通过import guardian
导入内容会产生importError。 This error occur even if I have the easy_install.pth
copied in 即使我已复制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)
Now, using easy_install django-guardian
, of course had no such problem. 现在,使用easy_install django-guardian
,当然没有这样的问题。
I navigated to the directory the egg file was easy_installed to, and all it contains was the .pth
and the .egg
file. 我导航到egg文件easy_installed到的目录,它包含的是.pth
和.egg
文件。 I wish to know what other procedures/entries does easy_install makes somewhere that makes the first method unusable.... 我想知道easy_install使得第一种方法无法使用的其他程序/条目....
easy_install
uses .pth
files to add the .egg
files to sys.path
-- the list of locations where Python searches for modules to import. easy_install
使用.pth
文件的添加.egg
文件sys.path
-位置列表,其中Python的搜索模块导入。
.pth
files are processed by the site
module, but only in four pre-defined directories. .pth
文件由site
模块处理,但仅在四个预定义目录中处理。 These directories are platform-specific and based on the sys.prefix
and sys.exec_prefix
settings. 这些目录是特定于平台的,并且基于sys.prefix
和sys.exec_prefix
设置。 On Unix, the most prominent usually is /usr/lib/pythonXX/site-packages
. 在Unix上,最突出的通常是/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
. 由于您的自定义目录不是site
处理的目录之一,因此不会处理.pth
文件,并且Python不会查看.egg
。
For more information, see the site
module documentation . 有关更多信息,请参阅site
模块文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.