pyAudioAnalysis
pyAudioAnalysis copied to clipboard
ImportError: failed to find libmagic
Got the following error when trying to execute python audioAnalysis.py fileSpectrogram -i data/doremi.wav from cmd
File "C:\Python27\lib\site-packages\magic.py", line 176, in
You need to install libmagic. I have not tried on windows but on MAC https://gist.github.com/eparreno/1845561 helped me. You may also need to install FFMPEG.
I'm having the same issue. When I tried, pip install libmagic in my anaconda python2 environment, I get an error: Requested Python version (2.7) is not installed. which doesnt make any sense.
https://github.com/tyiannak/pyAudioAnalysis/issues/109
Thanks to RasimusM and francesco1119.
Download and install (with pip install -r ) Windows-specific whl-file from https://pypi.python.org/pypi/python-magic-bin/0.4.14
This did it for me.
@divyanshu13 Did you solve the issue? @viveksj I am not able to run a pip install with -r, and the usual install does not solve the problem for me. When I try installing I get this message:
Requirement already satisfied: python-magic-bin==0.4.14 from file:///C:/Users/Lenovo/venv2/python_magic_bin-0.4.14-py2.py3-none-win_amd64.whl in c:\users\lenovo\anaconda2\lib\site-packages__
@neethusundarprasad I was able to resolve this issue by removing the conda environment, creating a new one and then repeating the steps. Another issue libav not found came up after which I switched form development in windows to unix.
@viveksj Thank you for the info. I was able to resolve it by switching to Unix.
pip uninstall python-magic pip install python_magic_bin-0.4.14-py2.py3-none-win32.whl that is useful for me on Windows environment
pip install python-magic-bin==0.4.14 You may also need to change the source code following https://github.com/tyiannak/pyAudioAnalysis/pull/160, which solved issue https://github.com/tyiannak/pyAudioAnalysis/issues/151 It works for me on Windows10 and python 3.6
on macos: if: pip install python-magic fails then: brew install libmagic (installed in /usr/local/Cellar/) then reference to libmagic in /usr/local/lib/ with: cd /usr/local/lib/ ln -s ../Cellar/libmagic/5.34/lib/libmagic.dylib libmagic.dylib
Only thing that worked for me so far (I am using google colab):
sudo apt-get install ffmpeg
sudo apt-get install python3-magic
pip install python-magic
I am a bit puzzled by all this MAGIC; perhaps somebody can explain.
My SlideSorter software (https://sourceforge.net/projects/slidesorter/ ) is running quite well on Linux (Ubuntu 16.04), and after some major fiddling now also on Windows.
My installations were all done via pip (last versions found): On Linux I have installed 'python-magic' (0.4.15) and all works fine. It does not hurt to also install 'libmagic' (1.0), but apparently it is not needed. Not available is 'python-magic-bin' ?
On Windows 10 Pro all I need is 'python-magic-bin' (0.4.14). Installing 'python-magic' instead does provide the module 'magic' to Python, but complains it can't find 'libmagic'. Surprisingly, installing 'libmagic' in addition does NOT provide this library. Huh?
So, in summary on Linux I need 'python-magic', on Windows I need 'python-magic-bin', and nothing else. True?
But I also want to offer this program for Mac. What installations do I need for Mac?
Installation
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 This module is a simple wrapper around the libmagic C library, and that must be installed as well:
Debian/Ubuntu
$ sudo apt-get install libmagic1
Windows
You'll need DLLs for libmagic. @julian-r has uploaded a version of this project that includes binaries to PyPI: https://pypi.python.org/pypi/python-magic-bin/0.4.14
Other sources of the libraries in the past have been File for Windows . You will need to copy the file magic
out of [binary-zip]\share\misc
, and pass its 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. Newer version can be found here: https://github.com/nscaife/file-windows.
OSX
When using Homebrew: brew install libmagic
When using macports: port install file
Ref:- https://pypi.org/project/python-magic/
In addition to @kushan-gunasekera's helpful answer, if you're running Python in a Docker environment (and using either Debian/Ubuntu, depending on what your Python image is based on) you need to run:
sudo apt-get install libmagic1
As part of your custom Dockerfile, at the time when all of the other system dependencies are installed.
This is because python-magic wraps libmagic which needs to be available at the system level, and without it, Python will complain that it can't find it in your container.
Dockerfile might look something like:
FROM python:3.9.6-slim-buster
ENV PYTHONUNBUFFERED 1
# Update repository sources list, install dependencies
RUN apt-get update \
&& apt-get install -y curl libmagic1 \
&& apt-get -y autoclean
cd /usr/local/lib
sudo ln -s /opt/homebrew/Cellar/libmagic/5.41/lib/libmagic.dylib libmagic.dylib