What's the bad magic number error?

后端 未结 15 2335
心在旅途
心在旅途 2020-11-22 16:56

What\'s the \"Bad magic number\" ImportError in python, and how do I fix it?

The only thing I can find online suggests this is caused by compiling a .py -> .pyc file

15条回答
  •  没有蜡笔的小新
    2020-11-22 17:35

    Take the pyc file to a windows machine. Use any Hex editor to open this pyc file. I used freeware 'HexEdit'. Now read hex value of first two bytes. In my case, these were 03 f3.

    Open calc and convert its display mode to Programmer (Scientific in XP) to see Hex and Decimal conversion. Select "Hex" from Radio button. Enter values as second byte first and then the first byte i.e f303 Now click on "Dec" (Decimal) radio button. The value displayed is one which is correspond to the magic number aka version of python.

    So, considering the table provided in earlier reply

    • 1.5 => 20121 => 4E99 so files would have first byte as 99 and second as 4e
    • 1.6 => 50428 => C4FC so files would have first byte as fc and second as c4

提交回复
热议问题