zipimport.zipimporter错误:zip缓存错误导致本地文件头错误?

2024-06-01 02:48:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试确定python使用的zip缓存机制中是否还有一个bug。原因是因为我正在运行的python代码将(似乎)随机失败,并出现zipimport.ZipImportError: bad local file header。在

它可能运行得很好,然后突然,ZipImportError当它试图导入我安装的自定义模块时(当它已经在执行的早期运行相同的代码时,可能会发生这种情况)。我不会在应用程序运行时更改自定义模块的egg文件,所以我有点左右为难。在

在google上搜索此错误的帮助时,出现了an old mailing list thread,其中说明

This might be due to:

http://bugs.python.org/issue856103

Specifically, zipimport's caching doesn't notice that it's not working on the same zipfile any more. easy_install is supposed to have some code in it to clear out the zipimport cache, but there is some possibility that it could have two versions of the path in there on a case-insensitive filesystem (e.g. Windows), and only one of them is getting cleared. Dunno if that's the case or not, but it might be something to look into. You could always stick a debugging print in the uncache_zipdir function and see if there's any correlation between what it's doing and when you're getting the error.

我不清楚链接错误的解决方法。在

我认为目前解决问题的唯一方法是将我的自定义模块标记为zip_safe=false。除非有什么方法可以禁用zip缓存或者类似的东西?在


Tags: 模块andtheto方法代码inthat