pygtk does not install correctly #16891

marcindulak opened this Issue Jan 4, 2013 · 22 comments

5 participants


This is problem reported originally at Homebrew/homebrew-science#53
pygtk related packages do not create correct links under /usr/local/include.
Creating links as listed above results in a matplotlib working with gdk backend
(no more "ImportError: No module named _backend_gdk")

@marcindulak marcindulak referenced this issue in Homebrew/homebrew-science Jan 4, 2013

pygtk does not install correctly #53


So there is the chance for an easy fix?


One has to set PKG_CONFIG_PATH correctly and additionally /usr/local/lib/pkgconfig/libffi.pc needs to be present (for some reasons it is not linked correctly from Cellar). So after libffi gets fixed, the correct variable would be:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig
The second dir is due to #14123


If pygtk uses libffi, it should have depends_on 'libffi'.


I guess @adamv is right; would be great if you could test this @marcindulak :-)


The problem (or feature) of the libffi.pc file missing is due the libffi formula itself.
So the question is: do i need to set the PKG_CONFIG_PATH before building pip install matplotlib or
this should be happening automatically?


A good question. Does pip install matplotlib read the PKG_CONFIG_PATH at all? (I haven't tested)


Yes it does


Then, perhaps, I can make a formula for matplotlib in my homebrew-python repository. Homebrew sets the PKG_CONFIG_PATH correctly during a build (if the depends_on lists the needed libs)


I understand now: homebrew sets the variables only within its own environment, so PKG_CONFIG_PATH
is not known the the shell, and this means some brew installed packages are not fully functional outside of brew.
Users need to keep track of this and set the variables by hand: #6828
Additional information: doing brew link libffi links the libffi.pc under /usr/local/lib/pkgconfig as expected,
but i understand there is a good reason the link is not performed for libffi.


Yes, Homebrew cannot set variables outside of its own process. Otherwise it would need to mess around with you .profile or whatever shell you are using.

You can call brew sh to temporary get the environment brew is using. I think this sets up the PKG_CONFIG_PATH, too. But I think not for keg_only formulae. Because these can break many other builds because they overwrite stuff from OS X.

Often one can set the path to a specific .pc file. But not sure if matplotlib allows this.


I'm building pip install matplotlib outside of brew with:
export PKG_CONFIG_PATH=brew --prefix libffi/lib/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
The X11 one is related to xquartz and there is some discussion here #14489


This is enough hassle. I am going to make a matplotlib formula in my homebrew-python tap.


Ok, here it comes:

brew tap samueljohn/python
brew install matplotlib --with-gtk

Let me know if there are any problems.


@marcindulak can you please give me feedback on the gtk backend in my matplotlib formula?

@adamv the pygtk formula has libffi indirectly in its deps, so I think it's okay.
This is more a matter of how to teach external python packages to use the one and not the other libffi, I think.

Therefore, in my opinion, we can close this. I am open for rants about my matlabformula in my repo :-)


@samueljohn there is a :tex requirement in core now


Closing in core; thanks.

@adamv adamv closed this Jan 14, 2013

@adamv I will note that down onto my todo list :-)


It looks to me that there are two problems in the matplotlib formula.
My perspective is the default OSX python:
1. line 69: PYTHONPATH is overwritten so matplotlib does not build with gtk (python -c "import gtk" fails if i add that to the install stage)
2. line 54: i think it should end with 'with-gtk'


@marcindulak you mean this line --> ?
True, I have less tested this with system python. Brewed python is fine. But I'll fix that.

To (2): Wow, good catch!


@samueljohn I was wondering if you could help me get pygtk up and running on my mac. I've brew installed python, pygtk, gtk and also your version of matplotlib. But if I type

import pygtk
import gtk
from gtk import gdk
import matplotlib
matplotlib.use('GTKAgg') # or 'GTK'
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas

I get an error

from matplotlib.backends._backend_gdk import pixbuf_get_pixels_array
ImportError: No module named _backend_gdk

If you have any suggestions I would be really grateful!

Homebrew member

Did you install matplotlib with --with-pygtk?

@xu-cheng xu-cheng locked and limited conversation to collaborators Feb 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.