Giter VIP home page Giter VIP logo

Comments (16)

SimonSapin avatar SimonSapin commented on May 31, 2024

The properties.py file has been there since forever, so the problem is most likely elsewhere. Is this the whole output? Are you using the same Python as the one Homebrew installed pygtk in? Did you create the virtualenv with --system-site-packages? Can you import pango from a Python shell? What about import lxml.etree?

from weasyprint.

ldiqual avatar ldiqual commented on May 31, 2024

Is this the whole output?

No, but everything else is related to Django. I noticed something else: when I load my django view for the first time (after starting the dev server), I get a ImportError: No module named gi.repository. Then, when I reload the page, it is replaced by ImportError: cannot import name properties.

Are you using the same Python as the one Homebrew installed pygtk in?

I don't think so, as $ which python outputs /usr/bin/python (v2.7.2). Do I have to use the Homebrew's python formula ?
I also followed the last step from Homebrew:

For non-Homebrew Python, you need to amend your PYTHONPATH like so:
  export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

Did you create the virtualenv with --system-site-packages? Can you import pango from a Python shell? What about import lxml.etree?

Yes, yes, and yes. I double checked that.

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

when I load my django view for the first time (after starting the dev server), I get a ImportError: No module named gi.repository

This is it. WeasyPrint fails to import Pango, either from gi.repository.Pango through PyGObject3-introspection or from just pango with PyGTK.

I really don’t know how Homebrew handles Python and Python libs. How do you start Django? Can you import pango with the same Python that Django uses?

from weasyprint.

ldiqual avatar ldiqual commented on May 31, 2024

Ok, you pointed out the right issue (I was importing cairo in my last test). Using ./manage.py shell, I get the same python environment than Django:

$ import pango
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named pango

$ import pygtk
# Seems to work

In /usr/local/lib/python2.7/site-packages (my PYTHONPATH):

$ find . -iname "*pango*"
./gtk-2.0/pango.so
./gtk-2.0/pangocairo.so

Is a pango.py needed ?

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

There is no pango.py, pango.so imports as a Python module. /usr/local/lib/python2.7/site-packages/gtk-2.0 should be in sys.path. On my system this happens because /usr/lib/python2.7/site-packages/pygtk.pth contains a path to the gtk-2.0 directory. Do you have something similar, maybe in another .pth file? If not try adding it. (But it should have been there…)

from weasyprint.

ldiqual avatar ldiqual commented on May 31, 2024

I have the same pygtk.pth file containing gtk-2.0. Plus, sys.path seems to be correct:

>>> import sys
>>> sys.path
[..., '/usr/local/lib/python2.7/site-packages', ...]

$ ls /usr/local/lib/python2.7/site-packages
...
gtk-2.0
pygtk.pth
pygtk.py
pygtk.pyc
pygtk.pyo
...

Any thoughts ?

from weasyprint.

ldiqual avatar ldiqual commented on May 31, 2024

I finally got it working ! Analyzing this PyGTK OSX package, I noticed that the postinstall script was adding the install path to /Library/Python/2.7/site-packages/gtkredirect.pth. So I modified it this way:

# in /Library/Python/2.7/site-packages/gtkredirect.pth
import site;
site.addsitedir('/usr/local/lib/python2.7/site-packages')

I think that brew just assume python to be installed with a brew package.
Thanks for your help Simon, you led me on the right way :)

Could you please add this step to the installation tutorial ?

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

'/usr/local/lib/python2.7/site-packages/gtk-2.0' needs to be in sys.path, no just '/usr/local/lib/python2.7/site-packages'. Did the .pth file exist before you set it to the above?

I’m not sure what happened on your system, but in any case WeasyPrint’s documentation is not the place to fix Homebrew’s PyGTK formula. I see that it has a warning about "non-Homebrew Python":
https://github.com/mxcl/homebrew/blob/master/Library/Formula/pygtk.rb#L24

Does that help, as an alternative to your fix?

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

If you undo these changes to your PyGTK install and got back to the default, does 35540be fix the issue? (It’s in git master.)

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

Closing, as I believe that 35540be fixed the issue.
Related: http://faq.pygtk.org/index.py?req=show&file=faq02.004.htp

from weasyprint.

marianobianchi avatar marianobianchi commented on May 31, 2024

I had this problem today while i was upgrading my django code on a server. The problem was that i didn't have pango1.0-dev installed on my system. I installed that library and everything works well now.

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

@marianobianchi I think yours was not exactly the same problem, since we’re not using PyGTK anymore. But thanks for sharing, I’ll remember to check the dependencies when debugging similar problems.

from weasyprint.

marianobianchi avatar marianobianchi commented on May 31, 2024

I know it is closed but after one year i run into the same problem again. I installed pycparser and everything seems to work fine again.

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

@marianobianchi Was pycparser not already installed as a (recursive) dependency?

from weasyprint.

marianobianchi avatar marianobianchi commented on May 31, 2024

I was having another problem and was installing all packages with "--no-deps" option in pip. That made me run into this problem again and found this old bug report. I thought it was a good idea to comment the solution that worked for me this time, but wasn't sure if this was the correct place to do it.

I have just installed using "pip install weasyprint" and it installed all the dependencies fine. So i think it's nothing to worry about...

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

Although the error message could definitely be better, I’m not too surprised that installing without dependencies doesn’t work.

from weasyprint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.