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 find any magic file
.So, I googled a little bit and found an answer here that gave me another error : File 5.3 supports only version 7 magic file. "magic.mgc" is version 12.
Can I get a magic file version 7 ?
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 themagic.pyc
files from your python lib folder. And if you downloadedzlib1.dll
,magic1.dll
,regex2.dll
andmagic.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
andregex2.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 themagic.mgc
file and press Ok.And Now It Should Work:
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 errorsFOR 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 theIncompleteRead
error, then type in your command line:For Python 2:
For Python 3:
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: