Installing libmagic in Mac OS X (for Python-magic)
When trying to install python-magic I found out that libmagic was not installed (or not properly available) in Mac OS X 10.7 Lion. There was little information on this problem on the Internet so I thought it might be helpful if I briefly wrote down my experiences.
When installing python-magic:
pip install python-magic
there was an error reported by ctypes (a depency that is installed as well). As ctypes should be part of your python (since 2.5) you can ignore this error or install python-magic from this updated version on GitHub: https://github.com/ahupp/python-magic
After the installation completes however, python-magic gives an error (libmagic not available):
>>> import magic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "[...]/python-magic/magic.py", line 128, in <module>
raise ImportError('failed to find libmagic. Check your installation')
ImportError: failed to find libmagic. Check your installation
The easiest way to install libmagic is through Homebrew, a Mac package manager. I used to resort to Fink or Macports in the past, but Brew seems a lot cleaner and more straightforward. Install Homebrew according to the instructions and then install libmagic:
brew install libmagic
Brew installs libmagic in /usr/local/Cellar/ . Python-magic however seems to be looking for a reference to libmagic in /usr/local/lib/
To solve this last problem we can create a symlink in /usr/local/lib to the right file.
ln -s ../Cellar/libmagic/5.04/lib/libmagic.dylib libmagic.dylib
After this, python-magic is able to find libmagic and works properly.