为什么我的 Python 2.6 在导入时不自动解压缩 Egg 文件?

发布于 2024-12-02 10:57:14 字数 418 浏览 6 评论 0原文

我的印象是Python导入应该自动 解压 site-packages 中的 Egg 文件。

我的安装似乎不想自动解压缩鸡蛋。我尝试过:

(1)我使用easy_install来安装suds模块,它复制了 Egg 文件放入站点包中。 Python 无法导入它。 (import suds)

(2) 然后我使用了 --always-unzip 选项来 easy_install。这次它 给了我一个目录而不是 zip 文件。 Python 仍然无法导入 suds 模块。

(3)我将目录重命名为suds。还是没找到。

(4)最后我将解压后的egg目录中的suds目录复制到 site-packags 和 Python 找到了它(这并不奇怪)。

对我来说,easy_install 不是。这里缺少什么?

鲁弗斯

I'm under the impression that Python import is supposed to automatically
unzip egg files in site-packages.

My installation doesn't seem to want to auto-unzip the egg. What I tried:

(1) I used easy_install to install the suds module, which copied the
egg file into site-packages. Python couldn't import it. (import suds)

(2) Then I used the --always-unzip option to easy_install. This time it
gave me a directory instead of a zip file. Python still couldn't import the suds module.

(3) I renamed the directory suds. still couldn't find it.

(4) finally I copied the suds directory out of the unzipped egg directory into
site-packags and Python found it (no surprise there).

for me, easy_install wasn't. What's missing here?

Rufus

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

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

发布评论

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

评论(1

往日 2024-12-09 10:57:14

默认情况下(如果您没有指定多版本模式),easy_installing Egg 会向 site-packages 中的 easy-install.pth 文件添加一个条目。检查那里是否有关于泡沫蛋的参考。您还可以检查 Python 导入路径(这是 Python 将搜索模块的位置列表),如下所示:

import sys
print sys.path

您是否在 easy_installed suds 之前启动的 Python shell 中尝试过 import suds
这可以解释你所看到的行为。 .pth 文件仅在 Python 启动时读取,因此 Egg 目录或 zip 文件不会出现在 sys.path 中。从 Egg​​ 目录中复制 suds 目录是有效的,因为 site-packages 本身已经在 sys.path 中。因此,请确保在安装 Egg 后重新启动 Python。

Python 将从 zip 存档导入,但不会将存档解压到站点包中。也就是说,导入后它不会将解压缩的目录保留在那里。 (我认为它会就地读取 zip 文件,而不将其提取到文件系统中的任何位置。)我见过一些包不能作为压缩鸡蛋工作的问题(他们试图从文件中的位置读取数据 -系统),所以我建议始终使用 --always-unzip 标志,就像在 (2) 中所做的那样。

您还没有给出您使用的命令行。您是否为 easy_install 指定了 -m 选项?这将导致egg以多版本模式安装。默认情况下它不会位于 sys.path 中,您需要在尝试导入它之前使用 pkg_resources.require 函数。

By default (if you haven't specified multi-version mode), easy_installing an egg will add an entry to the easy-install.pth file in site-packages. Check there to see if there's a reference to the suds egg. You can also check the Python import path (which is the list of places Python will search for modules) like this:

import sys
print sys.path

Did you try import suds in a Python shell that was started before you easy_installed suds?
That would explain the behaviour you saw. The .pth files are only read at Python startup, so the egg directory or zip file wouldn't have appeared in sys.path. Copying the suds dir from inside the egg directory worked because site-packages itself was already in sys.path. So make sure you restart Python after installing an egg.

Python will import from zip archives, but it won't unzip the archive into site-packages. That is, it won't leave the unzipped directory there after you import. (I think it reads from the zip file in-place without extracting it anywhere in the file system.) I've seen problems where some packages didn't work as zipped eggs (they tried to read data from their location in the file-system), so I'd recommend always using the --always-unzip flag as you do in (2).

You haven't given the command lines you used. Did you specify the -m option to easy_install? That will cause the egg to be installed in multi-version mode. It won't be in sys.path by default, and you'd need to use the pkg_resources.require function before trying to import it.

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