Closed GiuseppeLeviBo closed 1 year ago
On Windows, you can obtain the dll by installing python-magic-bin (additionally to python-magic) with pip install python-magic-bin
. Source: https://pypi.org/project/python-magic/
Same issue in Windows with installed python-magic-bin
and python3.
When I installed python-magic
and python-magic-bin
in virtualenv, it doesn't work too.
Problem with loading libmagic library in loader.py.
It tries to load libmagic.dll from current folder (./libmagic.dll) or tries find it in %PATH%.
But binary libraries from python-magic-bin installed in magic/libmagic folder.
Workarounds:
Steps for reproduce issue in Windows:
python-magic
, python-magic-bin
I can still reproduce this issue with Python 3.10.2 + python-magic 0.4.25 + python-magic-bin 0.4.14.
If you install python-magic-bin
after python-magic
then everything works. Because python-magic-bin overwrites magic/__init__.py
and load DLL from libmagic folder.
If you install python-magic-bin
before python-magic
then it doesn't work.
If you only install python-magic-bin
then it also works. However, you can't install python-magic-bin
on linux.
Before this issue is fixed, I think you have to specify your dependencies as:
python-magic-bin; sys_platform == "win32" or sys_platform == "darwin"
python-magic; sys_platform != "win32" and sys_platform != "darwin"
@eight04 this does not work as the init.py file is where the code of python-magic
is located, so you lose all updates. Notably, from_buffer
will no longer work as intended as the version exposed by python-magic-bin
does not encode the buffer so everything is application/octet-stream
. The only method at the moment to retain current functionality is to add the libraries to PATH. This information should really be exposed somewhere extremely obvious, python-magic-bin
is recommended as the installation method for windows yet it does not work.
For now I will manually installing libmagic
onto windows with https://github.com/pidydx/libmagicwin64 and removing python-magic-bin
from my requirements
Thanks @eight04! Uninstalling and installing python-magic first fixed my issue. Any objections to just adding a note to the readme on the correct installation order?
Merging into https://github.com/ahupp/python-magic/issues/293
Hi I have installed the library via pip and received no warning then when I try to import it libmagic is not found: PS G:\Pythontest> pip install python-magic Collecting python-magic Downloading python_magic-0.4.24-py2.py3-none-any.whl (12 kB) Installing collected packages: python-magic Successfully installed python-magic-0.4.24 PS G:\Pythontest> python Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
How to install the missing library and why pip has not installed it? (or at least failed to install ?)