10

I am trying to install python-magic for Windows and I have followed all the instructions in https://github.com/ahupp/python-magic and repeated the process several times but I am still getting this error:

ImportError: failed to find libmagic. Check your installation

I have magic1.dll (along with the two other files the docs specified) in C:\Windows\System32 so I am not sure what the issue is. I would appreciate any help or workarounds.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
wlingke
  • 4,699
  • 4
  • 36
  • 52

5 Answers5

9

Go here and download the file "python_magic_bin-0.4.14-py2.py3-none-win32.whl", then

pip install python_magic_bin-0.4.14-py2.py3-none-win32.whl

now python-magic works

enter image description here

Francesco Mantovani
  • 10,216
  • 13
  • 73
  • 113
6

I know this is a Windows question, but i wanted to share a Debian solution:

apt-get install libmagic-dev

Kind regards.

bubli
  • 93
  • 1
  • 1
3

The below original answer is now outdated. Please simply follow the instructions denoted under the "dependencies" section.


ORIGINAL ANSWER:

I was able to solve this problem by moving the 3 files from GNUWin32 project to a separate directory (not the \system32 directory the docs suggest) and adding them to the PATH environment variable

wlingke
  • 4,699
  • 4
  • 36
  • 52
  • 1
    which files? where did you put them? – stratis Apr 22 '14 at 13:47
  • 2
    I think this answer is outdated now. There used to be 3 files you had to manually deal with. now you should just follow the directions under "Dependencies" – wlingke Apr 22 '14 at 18:22
2

Follow the below steps.

  1. go to > https://github.com/pidydx/libmagicwin64
  2. download the 3 files (dll's) except readme.md file
  3. Drop the 3 files (dlls ) in C:\Windows\System32 and python magic will import correctly.
  • I am getting "ImportError: failed to find libmagic. Check your installation", using PyCharm. – Matt Nov 10 '22 at 10:10
0

Installing Cygwin with libmagic libary and installing the most recent version of the module from Github solves this problem.

At the time this question was asked, https://github.com/ahupp/python-magic probably didn't support cygmagic-1.dll.

Jakub Czaplicki
  • 1,787
  • 2
  • 28
  • 50