Skip to content

Instantly share code, notes, and snippets.

@tomekwojcik
Created May 23, 2012 22:45
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomekwojcik/2778301 to your computer and use it in GitHub Desktop.
Save tomekwojcik/2778301 to your computer and use it in GitHub Desktop.
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.

@djorlando24
Copy link

PythonMagick is working on MacOS Big Sur 11.2.3 with Homebrew and python 3.9
here are my installation steps. After having already installed homebrew;

  1. Install dependencies, including the llvm clang compiler which is required to use OpenMP, since XCode's clang doesn't support it.
    brew install python3 boost boost-python3 imagemagick llvm
    This will take a while.

  2. Get source
    git clone https://github.com/ImageMagick/PythonMagick
    cd PythonMagick

  3. Edit configure to correctly locate boost-python by replacing two instances of ax_python_lib=boost_python with ax_python_lib=boost_python39. My entries appear on lines 17992 and 18414. Your exact version of boost_python may vary in future, so check ls -l /usr/local/lib/libboost_python* first to see).

  4. Set BOOST_ROOT (your version may vary)
    export BOOST_ROOT=/usr/local/Cellar/boost/1.75.0_2

  5. Run the configure script, telling it explicitly where to find the correct compilers (llvm clang) and which python version and boost libraries to use. Your versions for boost and python may vary.
    ./configure CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++ PYTHON=python3.9 CPPFLAGS="-I/usr/local/Cellar/boost/1.75.0_2/include" LDFLAGS="-L/usr/local/lib"

  6. If the above works, then all that is required now is make; make install

If the linking step fails during make with an error such as ld: library not found for -l-L/usr/local/Cellar/imagemagick... then this indicates that libboost_python wasn't found by the configure script; the hanging -l is meant to point to -lboost-python39 or similar.

Similarly, if you get 'symbol not found' errors at runtime in python, this also indicates a failure to link to libboost-python. Make sure you've run brew install boost-python3 and use brew doctor to check for any broken links. Also make sure you're not linking against any "legacy" libraries, especially if like me you upgraded to Big Sur over the top of Mojave or Catalina. You might want to wipe away libboost_python and completely reinstall it if this happens.

  1. Go to anywhere other than the PythonMagick directory or its parent directory & run python3 -c 'import PythonMagick'. If successful, there should be no output / errors.

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