本文介绍了如何从不同版本的python导入* .pyc文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了python 2.5并从C:\ util \Python25 \Lib \site-packages目录导入了一个名为irit.py的文件。这个文件导入文件_irit.pyc,它位于同一目录。它工作得很好,做了我想要的。
比,我用python版本2.6.4尝试了同样的事情。irit.py这是在C:\util \Python26 \Lib\site-packages中导入了,但是_irit.pyc(与26之前的目录一样,在此之前)还没有找到。我收到了错误信息:

I used python 2.5 and imported a file named "irit.py" from C:\util\Python25\Lib\site-packages directory. This files imports the file "_irit.pyc which is in the same directory. It worked well and did what I wanted.Than, I tried the same thing with python version 2.6.4. "irit.py" which is in C:\util\Python26\Lib\site-packages was imported, but "_irit.pyc" (which is in the same directory of 26, like before) hasn't been found. I got the error message:

文件C:\ util\Python26 \lib \site-packages \irit.py,第5行,
导入_irit
ImportError:DLL加载失败:找不到指定的模块。

File "C:\util\Python26\lib\site-packages\irit.py", line 5, inimport _iritImportError: DLL load failed: The specified module could not be found.

有人可以帮助我理解问题以及如何解决它吗?
谢谢,Almog。

Can someone help me understand the problem and how to fix it??Thanks, Almog.

推荐答案

DLL加载失败无法直接引用。 pyc ,因为那是一个字节码文件,而不是DLL; Windows上的DLL将是 .pyd 。所以可能是 _irit.pyc 字节码文件尝试导入一些 .pyd 以及 .pyd 在相应目录中的2.6兼容版本中不可用。不幸的是,似乎源文件 _irit.py 也不存在,因此错误信息的结果可能不那么有用。我尝试运行 python -v ,它会在所有模块加载和卸载操作上给出详细消息 - 这可能会让你推断出缺少的<$ c的名称$ c> .pyd 比较2.5和2.6中的行为时。

"DLL load failed" can't directly refer to the .pyc, since that's a bytecode file, not a DLL; a DLL would be .pyd on Windows. So presumably that _irit.pyc bytecode file tries to import some .pyd and that .pyd is not available in a 2.6-compatible version in the appropriate directory. Unfortunately it also appears that the source file _irit.py isn't around either, so the error messages end up less informative that they could be. I'd try to run python -v, which gives verbose messages on all module loading and unloading actions -- maybe that will let you infer the name of the missing .pyd when you compare its behavior in 2.5 and 2.6.

这篇关于如何从不同版本的python导入* .pyc文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:53