9

Here's what I've done so far:

I've installed Homebrew:

/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

Then python: brew install python

Then py2cairo: brew install py2cairo

both of these seem to install correctly, and when I type which python I get: usr/local/bin/python which I believe is homebrew's version.

I've edited my path as many Homebrew guides have advised:

export PATH=/usr/local/bin:/usr/local/share/python:$PATH

Here's what I get from echo $PATH: /usr/local/bin:/usr/local/share/python:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

I can also type python --version and get python 2.7.3 which seems right because if I look in /usr/local/Cellar/py2cairo/1.10.0/README it says:

Dependencies
------------
    cairo   >= 1.10.0
    Python  >= 2.6 

However after all this I'm still unable to import the py2cairo library into python. Here's what I get when I try:

Sal:~ Lockyer$ python
Python 2.7.3 (default, May  6 2012, 13:47:31) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort trap: 6

I think most people use pip or easy_install for this kind of thing, but I don't think py2cairo is supported by those. Here's what I get when I run pip-2.7 install py2cairo:

Downloading/unpacking py2cairo
  Could not find any downloads that satisfy the requirement py2cairo
No distributions at all found for py2cairo
Storing complete log in /Users/Lockyer/Library/Logs/pip.log

I think I must just be missing one final step where I somehow reveal to python where to import the library from... am I forgetting to add something to my path?

Here's what I get when I run ls -l /usr/local/bin/python

lrwxr-xr-x  1 Lockyer  admin  33  6 May 13:48 /usr/local/bin/python -> ../Cellar/python/2.7.3/bin/python

Here's what I get when I run otool -L /usr/local/Cellar/py2cairo/1.10.0/lib/python2.7/site-packages/cairo/_cairo.so:

/usr/local/Cellar/py2cairo/1.10.0/lib/python2.7/site-packages/cairo/_cairo.so:
    /private/tmp/homebrew-py2cairo-1.10.0-BtmY/py2cairo-1.10.0/build_directory/src/_cairo.so (compatibility version 0.0.0, current version 0.0.0)
    /usr/local/Cellar/cairo/1.10.2/lib/libcairo.2.dylib (compatibility version 11003.0.0, current version 11003.2.0)
    /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.1)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1094.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

Moving /System/Library/Frameworks/Python.framework/Versions to my desktop, and running brew install py2cairo again seems to have fixed the error. It would be nice to know why it was building against Lion's python though because it doesn't seem to be first on the path...

Lockyer
  • 1,311
  • 1
  • 13
  • 30
  • If you had a previous python installed, it could still be that one. Post results of ls -l /usr/local/bin/python – jdi May 06 '12 at 17:04
  • I've edited the question with my results, looks like what you might expect to me? But I could be missing something... – Lockyer May 06 '12 at 17:11
  • Yea that looks right. I think @Dougal is probably on to your problem, suggesting that cairo itself may not have built properly. You are missing the underlying C extension – jdi May 06 '12 at 17:14
  • I think you should provide the last paragraph on your question as the correct answer instead of the one below. I've tried everything on this thread and the only thing that worked was your workaround. There's also some debate about this topic on [GitHub](https://github.com/mxcl/homebrew/issues/12893) – Rodrigo Jul 01 '12 at 17:53

4 Answers4

6

I stumbled upon this same error. Through some googling, I found out that this issue had already been detected on the issues page for the project on GitHub.

This seems to be a problem on how waf handles library imports, which I didn't understand fully. A fix has already been submitted and is pending approval.

If someone still runs into this problem before they accept the fix, it is possible to install the fixed formula for py2cairo following the commands proposed on this answer.

brew rm -f py2cairo
brew install  https://raw.githubusercontent.com/2bits/homebrew/15b3e67/Library/Formula/py2cairo.rb

When the fix is approved, a simple brew update should fix the problem.

Rodrigo
  • 5,938
  • 6
  • 31
  • 39
  • 2
    FYI, it's fixed in the latest Homebrew. `brew update` and `brew rm -f py2cairo && brew install py2cairo` worked for me. Thanks everyone who investigated this issue. Y'all saved me hours of trouble. – Neil Traft Jul 26 '12 at 01:00
  • 3
    a4e87cd has gone, try brew install h t t p s://github.com/2bits/homebrew/raw/15b3e67/Library/Formula/py2cairo.rb – Dr BDO Adams Dec 07 '12 at 10:13
  • 404. use ^^^ https://github.com/2bits/homebrew/raw/15b3e67/Library/Formula/py2cairo.rb – circuitry Feb 27 '14 at 21:31
4

As per your other comments, you have managed to resolve your library path issues, but you are left with the "Fatal Python error: Interpreter not initialized (version mismatch?)". Here is how to resolve it.

  1. Make sure you have xcode 4.3
  2. Make sure you have xcode command line tools installed
  3. brew tap homebrew/dupes && brew install homebrew/dupes/apple-gcc42
  4. sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2
  5. Confirm all of this with brew --config (should report GCC-4.2 located)
  6. brew uninstall cairo py2cairo
  7. brew install py2cairo --use-gcc

I had this same issue, until I built it with gcc, which is apparently not included in xcode 4.3 anymore.

Also, I am not using the homebrew python install (if you did that). I am using the standard apple python installation, and just have /usr/local/lib/python2.7/site-packages at the front of my PYTHONPATH

jdi
  • 90,542
  • 19
  • 167
  • 203
  • hmm, yeah adding `/usr/local/lib/python2.7/site-packages` to my `PATH` and using the default python install probably would have worked better. It's probably less sketchy then moving Library files around too... I didn't end up needing to install gcc through Homebrew though. – Lockyer May 06 '12 at 18:53
  • @Lockyer: I was getting the crash in every combination, until I finally installed and linked GCC to the right spot and homebrew acknowledged it, and I used the `--use-gcc` flag – jdi May 06 '12 at 18:55
  • @Rodrigo: thats not a fully complete error. Its just the command that failed. You have gcc installed, right? – jdi Jul 01 '12 at 17:51
  • @jdi thanks a lot for the feedback, but I've solved the problem as proposed on the last paragraph of the question: by moving the `/System/Library/Frameworks/Python.framework/Versions` to the Desktop before installing py2cairo. As you might see below, I've also discovered a more elegant solution through a fix proposed for the project. – Rodrigo Jul 02 '12 at 00:45
3

It seems like pycairo's waf installer file is finding the wrong python when installing. Can you run

otool -L /usr/local/Cellar/py2cairo/1.10.0/lib/python2.7/site-packages/cairo/_cairo.so

to determine which python the C extension is linked against? Mine includes a line like

/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.1)

(but I use the system python, not Homebrew python).

Danica
  • 28,423
  • 6
  • 90
  • 122
  • Sorry I had tried that before, and it had failed. I just messed it up when I was doing the write up for this question. Just tried it again, and edited my question with the results. – Lockyer May 06 '12 at 17:06
  • Aha, different problem. Try looking in `/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/cairo/` and `/usr/local/Cellar/py2cairo` for a file named `_cairo.so`, which is the C extension that py2cairo uses. It might be a path problem in finding that, or it might not have been built properly. – Danica May 06 '12 at 17:09
  • There's a `_cairo.so` at: `/usr/local/Cellar/py2cairo/1.10.0/lib/python2.6/site-packages/cairo`, but there's nothing except: `__init__.pyc` at: `/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/cairo` – Lockyer May 06 '12 at 17:14
  • Hmm -- not sure why it's in `lib/python2.6`; when I just did it I got `lib/python2.7`. The py2cairo `waf` installer seems to have picked up the wrong python version when you installed it. One easy workaround may be to (now that you have the dependency `cairo` through homebrew) just use pip-2.7 to install py2cairo.... You could also try `brew uninstall py2cairo; brew install py2cairo` and see if it happens again -- may have been an environment change when you installed it earlier, if you had just installed brew/python. – Danica May 06 '12 at 17:17
  • Ok, Just ran `brew uninstall py2cairo`, `brew install py2cairo`. Now there's a `_cairo.so` file at `/usr/local/Cellar/python/2.7.3/lib/python2.7/site-packages/cairo/`, and `/usr/local/Cellar/py2cairo/1.10.0/lib/python2.7/site-packages/cairo`. However now I get a different error when I try to import: `>>> import cairo Fatal Python error: Interpreter not initialized (version mismatch?) Abort trap: 6` – Lockyer May 06 '12 at 17:26
  • Sadly I don't think you can download py2cairo with pip either. I get this when I try: `No distributions at all found for py2cairo` – Lockyer May 06 '12 at 17:44
  • It's called `pycairo` in pip, but that doesn't work for me either (in 2 or 3). Can you try the thing in my edited answer? – Danica May 06 '12 at 17:56
  • hmm, mine contains the same string: `/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.1)` (see question for the rest of the output) does that mean it's built with Lion's python, while I'm trying to run it in Homebrew's? – Lockyer May 06 '12 at 18:09
  • Downvoted because, even though this answer provides information on the problem, accepting it as **the answer** is misleading in that it doesn't provide a working solution to the problem. The only thing that worked for me was the workaround proposed on the last paragraph of the question. – Rodrigo Jul 01 '12 at 17:58
0

For me also brew rm -f py2cairo and brew install py2cairo worked

Instead of

brew rm -f py2cairo

try

brew install  https://raw.githubusercontent.com/2bits/homebrew/15b3e67/Library/Formula/py2cairo.rb
SHR
  • 7,940
  • 9
  • 38
  • 57