Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Homebrew to install Python libraries like Py2Cairo

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...

like image 606
Lockyer Avatar asked May 06 '12 16:05

Lockyer


People also ask

Should you install Python with homebrew?

Don't use Homebrew Python. It's not meant for you. At some point Homebrew made changes that adversely affect Python development.

How do I manually install a Python package?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

Where are Python libraries installed?

Locally installed Python and all packages will be installed under a directory similar to ~/. local/bin/ for a Unix-based system, or \Users\Username\AppData\Local\Programs\ for Windows.

How do I download pip for Python?

Step 1: Download the get-pip.py (https://bootstrap.pypa.io/get-pip.py) file and store it in the same directory as python is installed. Step 2: Change the current path of the directory in the command line to the path of the directory where the above file exists. Step 4: Now wait through the installation process.


1 Answers

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.

like image 191
Rodrigo Avatar answered Oct 23 '22 06:10

Rodrigo