python-magic installation challenges for 64-bit Windows 10 running 32-bit Python 2.7 build

10.6k Views Asked by At

Despite following the readme for the module, I continue to get "magic files not found". The readme and "Dependencies" section say:

On Windows, copy magic1.dll, regex2.dll, and zlib1.dll onto your PATH from the Binaries and Dependencies zip files provided by the File for Windows project. You will need to copy the file magic out of [binary-zip]\share\misc, and pass it's location to Magic(magic_file=...) If you are using a 64-bit build of python, you'll need 64-bit libmagic binaries which can be found here: https://github.com/pidydx/libmagicwin64 (note: untested).

The following clarifications would be helpful:

1) The Files for Windows link provided has a link to "file-5.03-bin.zip" (labeled "Binaries"), a link to "file-5.03-dep.zip" (labeled "Dependencies"), and a link on the bottom right to "file-4.26-dep.zip", which is also labelled "dependencies file". I am assuming that the last is an error, which should point to 5.03-dep, rather than another second dependencies file which is required. Correct?

enter image description here

2) There appears to be a 32 bit version and a 64 bit version of the dependencies files. I don't know which version to use with 64-bit Windows but 32-bit Python. The instructions above say 64 bit Python, but this says 64 bit Windows. Which should I install?

3) The above says to put the DLLs in the PATH; the 64-bit instructions says to put them in C:\Windows\System32. Does it matter, as long as the folder is PATH'd? (Someone else suggested that specifically NOT putting them in \Windows\System32 helped: Python-magic installation error - ImportError: failed to find libmagic).

4) The above suggests that the only other file needed in the binaries and dependencies, other than the 3 DLLs, is the file magic. So I don't also need the file magic.mgc, which is also in the binary zip\share\misc? Nor do I need any of the other files in these two ZIPs, like the file file?

5) The above suggests to get the file magic out of the binary ZIP and put its path in a line of code which says: Magic(magic_file=...). I assume this is actually magic.Magic(magic_file='C:\path\goes\here\magic') AND I assume this can go anywhere in the file system.

6) .. and I assume, again, I'm pointing to the file magic rather than the file magic.mgc.

Are these assumptions correct?

2

There are 2 best solutions below

2
On

1) Yes, I think you should download 5.03. Not 4.26.

2) If you have 32-bit python, then download the 32-bit stuff.

3) As long as the dlls are in the system PATH variable, you are fine.

4) Yes. I think you are right.

5) I think that this is true.

6) they are completely different files. magic seems like the correct one because it seems to contain settings and information about what the magic should do.

2
On

I figured out what I was missing. I'll post it here in case anyone else is going crazy.

  1. Install:

    pip install python-libmagic

    pip install python-magic-bin

  2. Install Visual C (VCforPython.msi from Microsoft website)