Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 602
Suzanne Avatar asked Jan 06 '17 23:01

Suzanne


People also ask

Which Python version is best for Windows 10 64 bit?

It is recommended to install the latest version of Python, which is 3.7.3 at the time of writing this article.

How do I install Python magic on Windows?

The current stable version of python-magic is available on PyPI and can be installed by running pip install python-magic . Other sources: PyPI: http://pypi.python.org/pypi/python-magic/ GitHub: https://github.com/ahupp/python-magic.

How do I import magic into Python?

python-import-magic packageImport automatically python modules using importmagic and then sort using isort. Default keybinding for file auto import Ctrl-Shift-Space . This package also provides an autocomplete provider to add missing imports from a suggestion list. This package needs python importmagic and isort.


2 Answers

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

pip install python-libmagic

pip install python-magic-bin

Install Visual C (VCforPython.msi from [Microsoft website][1])
like image 189
Suzanne Avatar answered Oct 10 '22 00:10

Suzanne


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.

like image 20
Leonid Avatar answered Oct 10 '22 00:10

Leonid