Posted by José Lopes.
How to fix an error like:
ImportError: Bad magic number in ../SOME_FILE.pyc
This kind of error is associated with the pyc file type. The solution is simple: delete all the existing files with this extension and run your scripts again.
It may seem a radical solution but it may spare you some time because many or all the files are affected. Nevertheless these files are re-created once you run your program.
The error happens when we are using different Python versions, either between users or after an upgrade.
This type of file stores a "magic number" that is specific for each Python release. Each time the file is called a verification is done to match the it the expected value.
For further information about the existence of this number you may check the source code at Python/import.c.