I got this error while running the Django app file that I had downloaded from GitHub. How can I solve this problem?
-
6Delete all `.pyc` files you downloaded with it. – Martijn Pieters Sep 24 '18 at 10:49
8 Answers
Please go to your home directory. And then:
sudo find . -name "*.pyc" -exec rm -f {} \;
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.

- 751
- 1
- 6
- 6
You can delete all the .pyc files in your folder to resolve it.
find . -name \*.pyc -delete

- 323
- 2
- 7
-
-
1@Hans You are both needlessly adding sudo to a command and also failing to properly quote an argument that might end up expanding. The original command is fine. – penguin359 Nov 22 '22 at 23:43
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.

- 1,048,767
- 296
- 4,058
- 3,343
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

- 5,767
- 8
- 33
- 62

- 85
- 1
- 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.

- 55
- 8
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.
-
You can also use [scoop](https://scoop.sh/) or [NuGet](https://www.nuget.org/downloads) to better manage your installed software on windows, and then the process of installing or uninstalling python will be significantly better. – guychouk Apr 17 '20 at 09:38