问题
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.
回答1:
"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.
回答2:
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.
来源:https://stackoverflow.com/questions/2705304/how-to-import-pyc-file-from-different-version-of-python