如何从不同版本的python导入*.pyc文件?
我使用 python 2.5 并从 C:\util\Python25\Lib\site-packages 目录导入一个名为“irit.py”的文件。该文件导入位于同一目录中的文件“_irit.pyc”。它运行良好并且做了我想要的事情。 然后,我用 python 版本 2.6.4 尝试了同样的事情。导入了位于 C:\util\Python26\Lib\site-packages 中的“irit.py”,但尚未找到“_irit.pyc”(与之前一样位于 26 的同一目录中)。我收到错误消息:
文件“C:\util\Python26\lib\site-packages\irit.py”,第 5 行,位于 导入_irit ImportError: DLL 加载失败: 找不到指定的模块。
有人可以帮助我理解这个问题以及如何解决它吗? 谢谢,阿尔莫格。
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:
File "C:\util\Python26\lib\site-packages\irit.py", line 5, in
import _irit
ImportError: DLL load failed: The specified module could not be found.
Can someone help me understand the problem and how to fix it??
Thanks, Almog.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“DLL load failed”不能直接引用
.pyc
,因为那是字节码文件,而不是 DLL;在 Windows 上,DLL 为.pyd
。因此,大概_irit.pyc
字节码文件尝试导入一些.pyd
并且.pyd
在 2.6 兼容版本中不可用适当的目录。不幸的是,源文件_irit.py
似乎也不存在,因此错误消息最终提供的信息较少。我会尝试运行python -v
,它会在所有模块加载和卸载操作上提供详细消息 - 也许这会让您推断出丢失的.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 runpython -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.Pyc 文件不保证跨 Python 版本兼容,因此即使您修复了丢失的 dll,您仍然可能会遇到问题。
Pyc files are not guaranteed to be compatible across python versions, so even if you fix the missing dll, you could still run in to problems.