Skip to content Skip to sidebar Skip to footer

Python Error : File 5.3 Supports Only Version 7 Magic File

I installed python-magic with magic1.dll, regex2.dll, and zlib1.dll files and it imports correctly but when I try to do for example m = magic.Magic() I get the error : Could not fi

Solution 1:

I searched a lot for a solution for this problem, but couldn't found. I was a little bit playing with magic files and suddenly it worked. So now I will write a step-by-step to resolve problems like mine or similar to mine for Windows and Linux Users.

FOR WINDOWS:

Step 1: Delete the magic.py and the magic.pyc files from your python lib folder. And if you downloaded zlib1.dll, magic1.dll, regex2.dll and magic.mgc, also delete them.

Step 2: Download this zip file and extract it.

Note :This zip file contains all what we need : magic.py ,magic.pyc, magic.mgc, zlib1.dll, magic.dll and regex2.dll.

Step 3: Then move magic.py ,magic.pyc and the DLL files to the python lib folder.

Step 4: Go to Computer Properties > Advanced System Settings > Environment Variables, and click on New.... In the variable name type : magic And in the other field enter the path to the magic.mgc file and press Ok.

And Now It Should Work:

>>>import magic>>>s = magic.Magic()>>>s.from_file("test.txt")
'ASCII text, with no line terminators'
>>>

Note :If you compile your program to EXE, make sure that the DLL files and magic.mgc are in the same folder as your EXE program to work properly. If you don't do that you will get errors


FOR LINUX:

If you are a Linux user and you have problems with magic, here are what you have to do:

Step 1: In your command line, type sudo pip install python-magic to install or to upgrade to the lastest version of python-magic. If you have the IncompleteRead error, then type in your command line:

For Python 2:

sudo apt-get remove python-pip && sudo easy_install pip

For Python 3:

sudo apt-get remove python3-pip && sudo easy_install3 pip

This will upgrade in a certain way your pip and remove the error. After it finished, type sudo pip install python-magic to install magic after the pip upgrade.

Then It should Work:

>>>import magic>>>s = magic.Magic()>>>s.from_file("test.txt")
'ASCII text, with no line terminators'
>>>

Post a Comment for "Python Error : File 5.3 Supports Only Version 7 Magic File"