[Django]-ImportError: bad magic number in 'time': b'\x03\xf3\r\n' in Django

74👍

Please go to your home directory. And then:

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

25👍

Finally, I found the answer, The project has .pyc files, which holds the previous version information and time date, so this error. After deleting those files I got the output.

24👍

You can delete all the .pyc files in your folder to resolve it.

find . -name \*.pyc -delete 

16👍

Included in your checkout are .pyc files. These are byte cache files, storing cached bytecode so Python can avoid having to parse and compile the source files. Unless you plan to distribute a project without source files, these should not be included.

Just delete all .pyc files located in the same directory as .py files.

The “magic number” in the error message is a version number for the bytecode stored, and specific Python versions only work with specific bytecode magic numbers; the number in your error is equal to 62211 in decimal (when interpreted as a little-endian number), which shows the .pyc files were created with a Python 2.7 interpreter.

Python 3.2 switched to storing .pyc files in separate __pycache__ directories and including the Python version in the filename. However, any .pyc files still located next to the .py files are supported still to allow for bytecode-only releases. It’s safe to delete such files because if you were to use a Python 2.7 interpreter in future, then the files will be re-created.

8👍

Delete the .pyc files created in your directory .’

ex : i have gitlab.py and gitlab.pyc

later i renamed it into gitlab-api.py

But while running python file , it is using gitlab.pyc so

Traceback (most recent call last):
File "gitlab-api.py", line 1, in
import gitlab
ImportError: bad magic number in ‘gitlab’: b’\x03\xf3\r\n’

it worked correctly when i deleted the gitlab.pyc

4👍

you will need to delete any pyc. pyc is the cache of your app. delete all files that end with .pyc and rerun your app.

👤Aziz

2👍

If your OS is Windows you have to delete Python’s older versions, then you are ready to use pip again. This is the best method, without errors.

👤cgomev

1👍

Rename the class name or file name that you are importing, this fixed my issue.

👤Yahya

Leave a comment