add cairo package in the anaconda python distribut

2020-04-14 09:10发布

问题:

I am new to using the anaconda distribution for python, and I have trouble installing the cairo package. Note that I am using Mac OsX.

I ran the following command conda install --channel https://conda.binstar.org/tshead2 cairo and the installation seems to work fine.

But in a python command line the "import cairo" throws a package not found excpetion.

I already tried to troubleshooting provided here, but no luck.

What am I doing wrong ?

回答1:

I just installed py2cairo under Anaconda, using autotools, and it seems to work fine. The alternate 'waf' install was problematic, in that it picked up another version of python installed on my system (not the one in my PATH), and while I was able to build py2cairo, anaconda python didn't like it.

Basic instructions for building from autotools are here. I assume that Anaconda is installed under /anaconda, and that the py2cairo tarball untars to py2cairo-1.10.1. Also, you will need autotools (available from Macports, for example).

  1. Untar py2cairo tarball under /anaconda/pkgs
  2. In pkgs/py2cairo-1.10.0, create a 'bootstrap' file containing the following commands :

    libtoolize --force
    aclocal
    autoheader
    automake --force-missing --add-missing
    autoconf
    

(autotools experts would be able to clarify the steps above. The problem I ran into was that running "configure" out of the box led to an error about "install.sh", etc. not being found. Re-creating the configure scripts with the above fixes this problem.)

  1. Run bootstrap

    pkgs/py2cairo-1.10.1 % sudo sh bootstrap
    

Alternatively, you could just run the bootstrap commands from the command line.

  1. Then, run 'configure', setting the prefix to your python installation :

    pkgs/py2cairo-1.10.1 % sudo configure --prefix=/anaconda
    
  2. Make and install as usual :

    pkgs/py2cairo-1.10.1 % sudo gmake
    pkgs/py2cairo-1.10.1 % sudo gmake install
    
  3. Test your installation with :

    % /anaconda/bin/python -c "import cairo"
    

I am not a Python export, and so welcome any comments on the above.



回答2:

Have you installed a package with Python bindings, such as PyCairo och cairocffi? If you haven't you won't be able to interact with Cairo from Python.

I've just spent way too much time trying to get this to work myself with Anaconda on my Mac. I couldn't get PyCairo to work at all, but I managed to get cairocffi installed and working through pip after a bit of fiddling.

If import cairocffi doesn't work and gives you an error message that ends with

OSError: cannot load library libcairo.so.2: dlopen(libcairo.so.2, 2): image not found

try export DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:/Users/your_username/anaconda/lib/ or whatever your Anaconda path is at the command line.

Also see https://github.com/SimonSapin/cairocffi/issues/29