I am trying to install py2cairo on a framework build (Mac OSX Lion) of python 2.7.3 using brew. I have been unsuccessful this far.
First, I tried a simple
brew install py2cairo
This seems to work only on a non-framework build of python. When I do this on my framework build python faults as soon as I import cairo with an incompatible binary error.
Second, I have tried to build it myself by grabbing it from github and issuing:
python waf configure
This fails with:
Checking for library python2.7 : not found
Checking for library python2.7 : not found
Checking for library python2.7 : not found
Checking for library python27 : not found
Checking for program python2.7-config : /usr/local/Cellar/python/2.7.3/bin/python2.7- config
Checking for header Python.h : Could not find the python development headers
The configuration failed
(complete log in /Users/tobin/tmp/py2cairo/build_directory/config.log)
I have tried everything at: How to install PyCairo 1.10 on Mac OSX with default python but none of this has helped.
It appears to me that this may be failing to find python2.7 library and header file since it is a framework build. Is that possible? I was looking at the brew formula and it appears that framework builds do not get --enable-share set at build time. I'm not sure if that is relevant here - but maybe one possibility.
Anyone other insights would be great. Thanks in advance.
I discovered that the inability to build py2cairo had to do with the use of the "-march=native" flag by gcc. gcc (4.2.1) on Mac OSX has issues with this. I then reinstalled gcc as well as python. Afterwards when building py2cairo with waf - it was getting "-march=core2" and everything built.
Unfortunately, not all is good yet. I get the same error when I import cairo from my build that I got from the brew version (as mentioned above). The exact error message is:
>>> import cairo
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort trap: 6
and then python exits.
It would now seem that the issue is related to the framework build of python. I tested it without a framework build and it worked fine.
So as to not leave this question dangling ... I wanted to follow up with my resolution and learning points:
As noted above there was an incompatibility with my version of OSX and a gcc compile flag called -march=native. In a later version it was coming up as -march=core2. This pretty much fixed itself with compiler/version changes after cleaning up my machine.
For years I have had quite a mess with all of my various MAC OSX installs - and accepting the "migration option". Two machines ago - I installed the python binaries for versions 2.4, and 2.5, Then eventually went to macports for various reasons. Then eventually went to homebrew. When I went to homebrew I tried to clean things up by hand (but of course this can be challenging). To make matters worse - everytime I have gotten a new mac (2 times) in the last 6 years I take "the migration install" option and this pushes the mess forward and makes it worse. So as I started looking into things further - I had various installs of python, with different versions - mac-native, python-native, mac ports, homebrew, and probably even others too on my system. So my best guess is that cairo was somehow finding one of these and trying to build against it.
I finally solved this by deleting a bunch of old python installs by hand and then starting over with a fresh virtualenv and homebrew install of python 2.7.
WARNING: I don't think that this is the smartest way to go. I was careful not to delete a version of Python that I thought came native with OSX Lion (I think it is 2.6) - but it is not clear how it may potentially effect some other things that may have depended on older mac installs of python. I ended up deleting a 2.3, a 2.4, and two different 2.5s - along with various links in some places. WHAT A MESS! Unless you are absolutely sure of what it is you are doing (which I was not) I would not suggest this approach. I was basically trying to kill 6 years of python install crud that has collected.
To be safe I probably should have started with a fresh OSX Lion install and then added my homebrew version and went from there. I will likely do this in the near future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With