Magicexception:File 5.41 Supports Only Version 16 Magic File, Magic.Mgc Is Version 14

File command error - how to update magic file

Perhaps you have more than one file executable in your $PATH. It can get confused if it finds a different database (magic) than it expected. File 5.29 (tagged October 2016) bumped the format to version 14. File 5.31 appears to be the current version on MacOS (works for me).

The "magic" file is built up from many smaller files (see git repository (mirror)). If you needed a specific version that's not prepackaged, you could download the source and compile it, starting with the project page, which points to an ftp site.

However, replacing that magic.mgc file runs into Apple's "system protection" (limited permissions). It's possible to turn that off (perhaps not a Good Idea®) But it's doable.

While you could replace the data file, it might be simpler to just install MacPorts and use the file package from that. It's currently at 5.32 (a step ahead of Apple's package), and if you did not like that, it's simpler to remove/alter.

Python Error : File 5.3 supports only version 7 magic file

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'
>>>


Related Topics



Leave a reply



Submit