Forums

Installing lxml in a virtualenv

I am having trouble installing lxml in a virtualenv I had to create to run Django 1.6. I am trying to install some packages to generate PDFs (see http://avedo.net/681/automated-pdf-reports-using-z3c-rml-and-preppy/ ), and one of the dependencies is lxml, which will not install without libxml2 and libxslt. Has anyone been successful installing these packages on a virtualenv, or have some suggestions for me to try?

Edit: I am currently on a free account, so attempting to install libxml2 via pip install ftp://xmlsoft.org/libxml2/python/libxml2-python-2.6.21.tar.gz as suggested on Stack Overflow ( http://stackoverflow.com/questions/3856468/how-to-install-libxml2-in-virtualenv ) gave me a 111 (connection refused) error. I requested whitelisting xmlsoft.org, but I'm not sure that would fix my problem because that is for the python bindings to libxml2, and I think I need to install the core C libraries (that being said, I really don't know).

Update: I believe I successfully installed libxml2 using the instructions from http://www.upfrontsystems.co.za/Members/hedley/my-random-musings/compile-and-install-libxml2-python

I can import libxml2 and libxml2mod from my virtualenv python installation.

Update: What I successfully installed was libxml2-python, which is not what lxml needs in order to install.

Since lxml is included on the main Python installation, is there some way to make lxml point to the libxml2 and libxslt installations on the PythonAnywhere server?

Sorry for the slow response! I've whitelisted *.xmlsoft.org, looking into whether there's anything else we need to do to get this working.

OK, it looks like the problem is when it compiles, it uses

x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/home/giles/.virtualenvs/lxmltest/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -w

There should be a -I/usr/include/libxml2/ in there. Investigating...

OK, this should do the trick:

CFLAGS=-I/usr/include/libxml2/ pip install lxml

Thanks a lot. Hopefully I can get this working. My alternative is to use a different host just for the PDF creation of my application and create a web service, but if I can get z3c.rml working on PythonAnywhere I'd much prefer that.

Makes sense. Just let us know if that doesn't work, and we can investigate further.

It worked! To anyone else trying to install z3c.rml (a package from Zope to generate PDFs from a template) on a virtualenv, if you first install lxml using the instructions above, you should be able to install z3c.rml next:

CFLAGS=-I/usr/include/libxml2/ pip install lxml
pip install z3c.rml

Thanks again for the great support!

Excellent! Glad to help :-)