20140301

.pyc "Bad magic number" solution

I am reporting this solution here for convenience.  Without going into specifics, the issue I had related to a Myth NetVision plugin.

I ran into an issue with a project that included only a .pyc file.  The file was compiled with Python 2.6, but the system standard Python was 2.7.  To make matters worse, several other .py files required 2.7, making reverting to 2.6 rather impossible.  The original source was not provided even in the sources; I suspect this was due to a license constraint.

The solution was to recompile the .py with 2.7.  However, to obtain the .py with going to the maintainers, I used a Python decompiler.  The following commands are what I used:
pip install unpyclib
python -m unpyclib.application -Dq path/to/file.pyc
Recompiling was as simple as moving the new source file into the directory along side the original .pyc, and deleting the .pyc before running the appropriate script (as root, due to permissions requirements).

References:
http://stackoverflow.com/questions/5287253/is-it-possible-to-decompile-a-compiled-pyc-file-into-a-py-file

Alternative Decompilers (untried):
http://stackoverflow.com/questions/5287253/is-it-possible-to-decompile-a-compiled-pyc-file-into-a-py-file
https://github.com/wibiti/uncompyle2