为什么我的Python 2.6导入时不自动解压缩egg文件? [英] Why doesn't my Python 2.6 auto-unzip egg files on import?

查看:55
本文介绍了为什么我的Python 2.6导入时不自动解压缩egg文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的印象是应该自动导入Python将鸡蛋文件解压缩到站点程序包中.

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)我使用easy_install来安装suds模块,该模块复制了鸡蛋文件放入站点包中.Python无法导入它.(进口肥皂水)

(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)然后,我将--always-unzip选项用于easy_install.这次呢给了我一个目录,而不是一个zip文件.Python仍然无法导入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)我重命名了目录suds.仍然找不到它.

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

(4)最后,我将suds目录从解压缩的egg目录中复制到了site-packags和Python找到了它(在那里不足为奇).

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

对我而言,不是easy_install.这里缺少什么?

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

Rufus

推荐答案

默认情况下(如果您未指定多版本模式),easy_installing一个鸡蛋会将条目添加到 easy-install.pth 站点包中的文件.检查那里是否有提到肥皂水的参考.您还可以像这样检查Python导入路径(这是Python将在其中搜索模块的位置的列表):

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

您是否尝试过在轻松安装suds之前启动的Python shell中 import suds ?那将解释您看到的行为. .pth 文件仅在Python启动时读取,因此egg目录或zip文件不会出现在 sys.path 中.从egg目录内部复制 suds 目录有效,因为 site-packages 本身已经在 sys.path 中.因此,请确保在安装鸡蛋后重新启动Python.

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将从zip归档文件中导入,但不会将归档文件解压缩到站点程序包中.也就是说,导入后不会将解压后的目录保留在那里.(我认为它是从zip文件中读取的,而不是将其解压缩到文件系统中的任何位置.)我已经看到了一些软件包不能用作压缩鸡蛋的问题(它们试图从文件中的位置读取数据,系统),因此我建议始终像在(2)中一样使用--always-unzip标志.

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

您尚未提供所使用的命令行.您是否为easy_install指定了-m选项?这将导致鸡蛋以多版本模式安装.默认情况下,它不会出现在sys.path中,并且在导入之前,您需要使用 pkg_resources.require 函数.

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.

这篇关于为什么我的Python 2.6导入时不自动解压缩egg文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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