Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: failed to find libmagic. Check your installation #145

Closed
CarlGalloy opened this issue Oct 3, 2017 · 11 comments · May be fixed by #294
Closed

ImportError: failed to find libmagic. Check your installation #145

CarlGalloy opened this issue Oct 3, 2017 · 11 comments · May be fixed by #294

Comments

@CarlGalloy
Copy link

Hi.
In dependency section mention that "magic1.dll, regex2.dll, and zlib1.dll onto your PATH from the Binaries " where exactly PATH is? ( System Environment PATH? )

@ahupp
Copy link
Owner

ahupp commented Oct 3, 2017

Yes, your %PATH% environment variable.

@CarlGalloy
Copy link
Author

Now i have this Error:

``

import magic
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\magic.py", line 154, in
libmagic = ctypes.CDLL(dll)
File "C:\Python27\lib\ctypes_init_.py", line 353, in init
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
``

I install python-magic using pip install magic-python and i can see files on pythonsite-packages installation directory.

What's wrong?
and a question: : we must pass location of magic file (from [binary-zip]\share\misc ) to Magic(magic_file=...) ? Like this below code?

f = magic.Magic(mime=True, uncompress=True,magic_file="./mymagicfile/magic")

@ahupp
Copy link
Owner

ahupp commented Oct 6, 2017

No, the magic_file argument won't help here. It's failing to load the libmagic dll for some reason. I generally like to use the "Process Monitor" utility from sysinternals to figure out where it's trying to load DLLs from. Either it's looking in the wrong place, or there's a missing dependency of those dlls.

@Ayla93
Copy link

Ayla93 commented Oct 23, 2017

Is the problem solved?

@ahupp
Copy link
Owner

ahupp commented Oct 23, 2017

@Ayla93: to be clear, this is a local install issue rather than a bug in the library. Are you seeing the same issue as @CarlGalloy ?

@theirfanirfi
Copy link

Where is the magic1.DLL and regex located in windows 10. I'm having the same import error.
Please help me out.

@ahupp
Copy link
Owner

ahupp commented Dec 4, 2017

Those are 3rd party libraries you'll have to install. The README file includes some pointers to them, and I've updated it with more info.

@ahupp ahupp closed this as completed Dec 4, 2017
@ysinjab
Copy link

ysinjab commented Mar 18, 2018

For me i faced this issue when I import magic library in my django application. I solved it by " brew install libmagic" installing libmagic on the system level

@ashishnitinpatil
Copy link

I had this issue with official python docker (python:3.7-slim-buster), so I fixed it with apt-get install libmagic-dev.

@jppg
Copy link

jppg commented Aug 12, 2020

I solve this problem with "pip install python-magic-bin"

@ye
Copy link

ye commented Feb 15, 2022

Yep, @ashishnitinpatil your comment was very helpful. The official python docker images is missing the (libmagic-dev for Debian based distro, headers, aka dynamic libraries files etc.), so we need to install libmagic-dev to make it work during the runtime (magic checks the dynamic libs). Alternatively, include the python-magic-bin version which includes those required files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants