Create a gist now

Instantly share code, notes, and snippets.

PythonMagick on OS X

Installing PythonMagick on OS X

  1. brew install boost - will take a lot of time and make your Mac hot
  2. brew install --with-magick-plus-plus imagemagick
  3. cd <path_to_PythonMagick_source>
  4. ./configure --with-boost=<path_to_boost_root>
  5. make
  6. make install
  7. python -c "import PythonMagick"

If PythonMagick build fails saying that it couldn't find -lboost_python navigate to <path_to_boost_root>/lib/, ln -s libboost_python-mt.dylib libboost_python.dylib and run make again.

Tested on 10.6.8 with Python 2.6.7 (custom build). Should work with Lion running stock 2.7.

NOTE: Looks like I was too quick to call it done. The module imports but raises exceptions when used. Bummer.

@Ringil
Ringil commented Jun 10, 2012

Did you ever figure out how to solve the import problem?

@tomekwojcik
Owner
@Ringil
Ringil commented Jun 11, 2012

I solved this problem by copying from where make install installed PythonMagick /usr/local/lib/python2.7/site-packages/PythonMagick to where Python actually looks on a OS X Lion, /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/

@nfglynn
nfglynn commented Jul 5, 2012

Just a quick note for anyone checking this in future, after successfully building PythonMagick on Mac OS X Lion I was getting:

>>> import PythonMagick
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "PythonMagick/__init__.py", line 1, in <module>
from . import _PythonMagick
ImportError: cannot import name _PythonMagick

This can be fixed by changing the first line of __init__.py in PythonMagick (Usually to be found in site-packages, in my case /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PythonMagick) from:

from . import _PythonMagick

to

import _PythonMagick
@slawek87

is there any howto about installing PythonMagick on mac os x? It's annoying problem.

@remymuhire

can find ./configure file .

RemyMuhire@Muhires-MBP:~$ cd /usr/local/Cellar/imagemagick/6.8.9-8
RemyMuhire@Muhires-MBP:/usr/local/Cellar/imagemagick/6.8.9-8$ ./configure --with-boost=/usr/local/Cellar/boost/1.56.0
-bash: ./configure: No such file or directory
RemyMuhire@Muhires-MBP:/usr/local/Cellar/imagemagick/6.8.9-8$

@DWishR
DWishR commented Nov 6, 2015

I got it working. Note that in the future boost/1.59.0 will change to something else.
Download PythonMagick-0.9.12 and unzip/untar/unwhatevs

$ brew install --with-magick-plus-plus imagemagick
$ brew install boost --with-python
$ brew install boost-python

$ cd ~/Downloads/PythonMagick-0.9.12
$ BOOST_ROOT=/usr/local/Cellar/boost/1.59.0/
$ ./configure

Now you need to edit Makefile and pythonmagick_src/Makefile to include the boost library. You want to find two lines, one that starts with DEFAULT_INCLUDES and the other with LDFLAGS. Add boost paths to the end of those lines so they look something like this:
DEFAULT_INCLUDES = -I. -I$(top_builddir)/config -I/usr/local/Cellar/boost/1.59.0/include
LDFLAGS = -L/usr/local/Cellar/boost-python/1.59.0/lib

$ make
$ make install

Edit __init__.py in the PythonMagick package folder, I found it at /usr/local/lib/python2.7/site-packages/PythonMagick. If you can't find the path, it should be at the end of the output of make install, on a line like: /bin/sh ./libtool --mode=install /usr/bin/install -c _PythonMagick.la '/usr/local/lib/python2.7/site-packages/PythonMagick'.

You want to change the first line of __init__.py from:

from . import _PythonMagick

to:

import _PythonMagick

And that should do it!

@rgvasquez
rgvasquez commented Jul 8, 2016 edited

@DWishR I was able to get through the instructions, but it still gives me "No module named PythonMagick" I noticed that even though I edited init.py, the corresponding init.pyc and init.pyo does not get rebuild when I import PythonMagick.

@corey-cole

@DWishR Just followed your instructions to a tee (correcting for new versions) and it worked perfectly. Thanks!

@nazikus
nazikus commented Nov 20, 2016 edited

@DWishR as of today, your solution still works, thanks.
PythonMagick-0.9.15
boost-1.62.0
boost-python-1.62.0

note: brew install --with-magick-plus-plus imagemagick gives warning
Warning: imagemagick: this formula has no --with-magick-plus-plus option so it will be ignored!
but nevertheless it worked, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment