Skip to content Skip to sidebar Skip to footer

Install Pycairo In Virtualenv

I've tried to install pycairo in a virtualenv to use in a Django project. I've ran the pip install pycairo==1.10.0 command which finds the package and downloads it unlike other com

Solution 1:

Good news, everyone!

I just released cairocffi: http://packages.python.org/cairocffi/

It’s a replacement for pycairo that installs with pip in a virtualenv, runs on Python 2 and 3, as well as PyPy.

pip install cairocffi

In your code:

import cairocffi as cairo
# Enjoy the same API as Pycairo.

Feedback welcome. (Although the issue tracker might be a better channel than here.)

Solution 2:

Although py2cairo doesn't install nicely using pip, you can still install py2cairo into the virtual environment using the build instructions in the INSTALL file from the distribution.

You will need the cairo-dev/cairo-devel package for you os installed in order to build the package.

Do the following to install into your virtual environment:

  1. download, unpack, and cd into the the py2cairo directory
  2. Activate your virtual environment
  3. Follow the standard build procedure

./waf configure --prefix=$VIRTUAL_ENV

./waf build

./waf install

Solution 3:

pycairo currently does not support installation through pip/distutils. The project’s install docs instructs to use either waf or autotools.

To use pycairo in a virtualenv, you need to:

  • Install pycairo system-wide, preferably through your distribution’s packages
  • Then, either:
    1. Create a virtualenv with the --system-site-packages option or remove the lib/pythonX.Y/no-global-site-packages.txt file after the fact.
    2. Or add a symbolic link to the cairo package (the directory containing _cairo.so). Something like this:
      ln -s /usr/lib/python2.7/site-packages/cairo ./venv/lib/python2.7/site-packages
      

Of course 1. has the downside that you will not profit from virtualenv’s isolation from other packages installed system-wide.

Solution 4:

For anyone trying to use pycairo (for Python 2.7) in conjunction with Homebrew and virtualenv --no-site-packages ... this Worked For Me:

  1. brew install py2cairo

  2. Then, find the path where Homebrew installed it to, will be something like:

    ls -l /usr/local/lib/python2.7/site-packages/cairo/
    total 24
    lrwxr-xr-x  1 anentropic  admin   80 10 Jun 14:26 __init__.py -> ../../../../Cellar/py2cairo/1.10.0/lib/python2.7/site-packages/cairo/__init__.py
    lrwxr-xr-x  1 anentropic  admin   78 10 Jun 14:26 _cairo.so -> ../../../../Cellar/py2cairo/1.10.0/lib/python2.7/site-packages/cairo/_cairo.so
    
  3. You want to find the path at the base of those symlinks, something like: /usr/local/Cellar/py2cairo/1.10.0/lib/python2.7/site-packages

  4. Then create a .pth file in your virtualenv site packages: echo "/usr/local/Cellar/py2cairo/1.10.0/lib/python2.7/site-packages" > venv/lib/python2.7/site-packages/cairo.pth

(may want to deactivate and re-activate your virtualenv for good luck, not sure)

Solution 5:

If cairocffi installation in virtualenv does not work and python-dev libffi-dev are unavailable (ArchLinux) setting environmental variable PKG_CONFIG_PATH=/usr/lib/libffi-3.2.1/include works.

Post a Comment for "Install Pycairo In Virtualenv"