I have some problems while trying to import some module (compiled .pyc) in my program. I know that it compiled in Python 2.6.6 (r266:84297), I have installed the same version, but had an error "bad magic number" while trying to import it :(
Does anybody know what I did wrong? Or maybe it's possible to change magic number in .pyc module?
As the answer linked by Matthew explains, your problem is almost certainly due to different versions of Python being used for compiling and loading the module. You can determine the magic number like this:
with open('pyuca.pyc', 'rb') as f:
print struct.unpack('<H', f.read(2))
You can determine your Python version by printing sys.version
(it is also echoed on interactive startup). If you are using Python 2.6.6, the magic number should be 62161. If it is different, you will need to switch to a different Python to be able to import the module.
The exact same applies to .pyo
files.
I solved this by running
find . -name '*.pyc' -exec rm {} +
which deleted all the pyc files in my directory. After that it was OK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With