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

2

13

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?

Grandchild answered 6/1, 2017 at 23:40 Comment(0)
G
17

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)

Grandchild answered 14/2, 2018 at 15:21 Comment(2)
As always, the bottom rated comment on stack overflow with the suspicious looking commands is the right one. Well done. To anyone reading this post, this is the right answer.Latter
Unfortunately, this link isn't valid any more. Could you figure out where VCForPython.msi can be found?Foetation
C
1

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.

Counterblast answered 3/2, 2017 at 15:10 Comment(2)
Thank you for answering. I've set all my settings accordingly and still can't get it to work.Grandchild
Error #1: need to install C for Python (which I did.) Then, error #2: "Unable to find magic library." Libraries pip-installed include: filemagic (1.6), file-magic(0.3.0), libmagic (1.0), python-magic (0.4.12), libarchive-c(2.7).Grandchild

© 2022 - 2024 — McMap. All rights reserved.