Fixing "Please make sure that Ghostscript is installed" for Camelot¶
When you try to use the camelot Python library, you might get the error message Please make sure that Ghostscript is installed
Quick solution¶
After installing ghostscript with brew install ghostscript
, run these commands to create a lib
folder for your user and link ghostscript to it.
Why this happens¶
When Camelot wants to use ghostscript, it uses ctypes.util.find_library('gs')
to find it.
If we look at the code for find_library
, we see that it searches through a few specific filenames:
from ctypes.macholib.dyld import dyld_find as _dyld_find
def find_library(name):
possible = ['lib%s.dylib' % name,
'%s.dylib' % name,
'%s.framework/%s' % (name, name)]
for name in possible:
try:
return _dyld_find(name)
except ValueError:
continue
return None
Mainly this uses dyld_find
, so I looked that one up, too. If we look at ctype's dyld.py we see there are some locations to look for libraries:
There are also some lines that work hard using all of the environment variables, including DYLD_LIBRARY_PATH
, DYLD_FALLBACK_LIBRARY_PATH
, and others.
The "easy solution" would have been to add your homebrew lib
folder to DYLD_FALLBACK_LIBRARY_PATH
whenever you start up your shell, but this (usually) doesn't work!
With newer versions of macOS that have SIP (System Integrity Protection) installed, all DYLD*
variables are pretty much disabled across the board, so while it might work in your terminal as soon as you launch any software (e.g. Python) it'll immediately disappear. If you've disabled SIP, though, it will work.
How I fixed it¶
While you could disable SIP, there's a (kind of? somewhat?) easier solution: put the library somewhere ctypes can find it.
If we go through the list of places it looks, os.path.expanduser("~/lib")
is at the top of the list. I used to force my students to symlink into /usr/local/lib
, but it seems cleaner to just push it into your actual user folder.
And now we're at our solution! Make a lib
folder in your user directory, then point it to the libgs.dylib
file that's sitting in the homebrew folder.
Python will be able to find it just fine, Camelot will be able to find it just fine, and it should (hopefully) work perfectly okay after upgrades and updates.