Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create stub package to use cairocffi as drop in replacement for pycairo #4

Closed
codeodor opened this issue Feb 10, 2013 · 6 comments
Closed

Comments

@codeodor
Copy link

I have next to no experience with Python, so I don't know if this is possible from your perspective or something I can only do locally.

I had a lot of trouble installing pycairo for use with some other Python programs that depend on it. Since I didn't write the code and did not want to keep local forks of each of the programs, I didn't want to use your recommendation to

import cairocffi as cairo (from http://stackoverflow.com/questions/11491268/install-pycairo-in-virtualenv/14205767#14205767)

In any case, I thought it would be great if there was a way to do that so you could force other packages to use cairocffi instead of pycairo.

I asked a Python programmer I know on Twitter:

twitter conversation about this request

So, is this something you can do at your level to make downstream consumption easy, or is it something only possible locally?

@SimonSapin
Copy link
Member

Hi,

I think you’re looking for cairocffi.install_as_pycairo(). What this function does is that if import cairo for from cairo import … is run later, cairocffi is imported instead of pycairo.

So if you’re using a Python library that itself uses pycairo, run this code:

import cairocffi
cairocffi.install_as_pycairo()

… before importing that library. Every thing should just work.

For a Python command-line tool where you’re not writing any Python code it’s a bit more tricky. Either:

  1. Patch the tool to add the code above so that it’s run as early as possible
  2. Write your own command line script that has the above code and then calls the tool’s main() function. Hopefully the tool has a well-delimited main function that you can import.

Does this help?

@codeodor
Copy link
Author

Yes, I think I'm going to have to do the latter, though I was hoping there was a way for you to distribute it that way for other folks who may not be comfortable or knowledgable enough to consider patching it themselves.

Thanks for the advice!

@SimonSapin
Copy link
Member

Yet another option is to have a cairo.py in your sys.path containing this:

from cairocffi import *

But this is more brittle because you have to make sure it takes priority over pycairo (or that pycairo is not installed, or use a virtualenv with --no-site-packgaes, …)

@codeodor
Copy link
Author

Actually, that's probably easier for my case. Thanks!

I did already have the virtualenv set up with that flag, and did not have pycairo set up to begin with.

@SimonSapin
Copy link
Member

@codeodor
Copy link
Author

codeodor commented May 1, 2013

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants