Bad Magic Number, Python3 Error

I just learned the hard way that if you have .pyc files in your dev environment, you’ll get this ugly motherload of an error when you try to run a python file using a python3 prompt:

ImportError: bad magic number in 'turtle': b'\x03\xf3\r\n'

You can clear out the .pyc files using this command:

find . -name "*.pyc" -exec rm -f {} \;

Or this one: find . -name \*.pyc -delete.

If you use a python prompt you may get this error instead:

AttributeError: 'module' object has no attribute 'Turtle'

FYI, that attribute error could also be from naming your file turtle.py, so I certainly won’t be making _that_ mistake (again).

My file is named kitten.py instead. =^_^=

Leave a Comment