Created
February 27, 2015 15:38
-
-
Save burnash/1f0615516ccdf826833c to your computer and use it in GitHub Desktop.
Installing py2cairo on OS X 10.8.5 in virtualenv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I ran into a problem when I was trying to import cairo installed into virtualenv | |
# | |
# >>> import cairo | |
# Fatal Python error: PyThreadState_Get: no current thread | |
# Abort trap: 6 | |
# After extensive search I found possible source of the problem. When installing py2cairo from source code waf | |
# builder links .so file to a wrong version of Python: | |
# $ otool -L ./build_directory/src/_cairo.so | |
# ./build_directory/src/_cairo.so: | |
# /Users/burnash/dist/py2cairo-1.10.0/build_directory/src/_cairo.so (compatibility version 0.0.0, current version 0.0.0) | |
# /opt/X11/lib/libcairo.2.dylib (compatibility version 11203.0.0, current version 11203.16.0) | |
# /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.2) | |
# /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0) | |
# Note link to /System/Library/Frameworks/Python.framework/Versions/2.7/Python which is a system python | |
# Below is solution that worked for me when I started from scratch: | |
brew install cairo | |
# Download py2cairo | |
tar -xjf py2cairo-1.10.0.tar.bz2 | |
cd py2cairo-1.10.0 | |
export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/cairo.pc:$PKG_CONFIG_PATH | |
# After this on my system echo $PKG_CONFIG_PATH gives: | |
# /opt/X11/lib/pkgconfig/cairo.pc:/usr/X11/lib/pkgconfig:/usr/local/Cellar/libpng/1.5.13/lib/pkgconfig:/usr/local/Cellar/freetype/2.4.10/lib/pkgconfig:/usr/local/Cellar/fontconfig/2.10.1/lib/pkgconfig:/usr/local/Cellar/pixman/0.28.0/lib/pkgconfig:/usr/local/Cellar/cairo/1.12.8/lib/pkgconfig:/opt/local/lib/pkgconfig | |
# Special thanks to: | |
# * http://stackoverflow.com/a/11286750/318359 | |
# * https://github.com/Homebrew/homebrew/issues/12893 | |
# * http://stackoverflow.com/a/9764104/318359 | |
# * http://www.niconomicon.net/blog/2011/10/09/wrestling-python-snow-leopard.html | |
export PATH=/Users/burnash/.pythonbrew/pythons/Python-2.7.3/bin:$PATH | |
export PYTHONPATH=/Users/burnash/.pythonbrew/pythons/Python-2.7.3/lib | |
export LD_LIBRARY_PATH=/Users/burnash/.pythonbrew/pythons/Python-2.7.3:$LD_LIBRARY_PATH | |
export LD_LIBRARY_PATH=/Users/burnash/.pythonbrew/pythons/Python-2.7.3/lib:$LD_LIBRARY_PATH | |
export LINKFLAGS='-search_dylibs_first -L /Users/burnash/.pythonbrew/pythons/Python-2.7.3/lib' | |
# From stackoverflow http://stackoverflow.com/questions/6886578/how-to-install-pycairo-1-10-on-mac-osx-with-default-python | |
export ARCHFLAGS='-arch x86_64' | |
# Replace /Users/burnash/projects/my_new_project/env with a path to your virtualenv | |
python waf configure --prefix=/Users/burnash/projects/my_new_project/env | |
python waf build | |
python waf install | |
# Test if cairo is linked to | |
otool -L ./env/lib/python2.7/site-packages/cairo/_cairo.so | |
./env/lib/python2.7/site-packages/cairo/_cairo.so: | |
/Users/burnash/dist/py2cairo-1.10.0/build_directory/src/_cairo.so (compatibility version 0.0.0, current version 0.0.0) | |
/opt/X11/lib/libcairo.2.dylib (compatibility version 11203.0.0, current version 11203.16.0) | |
/Users/burnash/.pythonbrew/pythons/Python-2.7.3/lib/libpython2.7.dylib (compatibility version 2.7.0, current version 2.7.0) | |
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment