I have been struggling to be able to do from lxml import etree (import lxml works fine by the way) The error is:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/lxml/etree.so, 2): Symbol not found: _htmlParseChunk
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/etree.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/etree.so
i used pip to install lxml, and homebrew to reinstall libxml2 with the right architecture (or so i think) …does anyone have ideas on how to fix/diagnose this? I’m on 64 bit python
lxmlis a bit fussy about what 3rd-party libraries it uses and it often needs newer versions than what are supplied by Apple. Suggest you read and follow the instructions here for buildinglxmlfrom source on Mac OS X including building its own statically linked libs. That should work. (I’m a little surprised that homebrew doesn’t already have an lxml recipe.)UPDATE: Based on the limited information in your comments, it is difficult to be sure exactly what is happening. I suspect you are not using the version of Python you think you are. There are any number of ways to install lxml successfully; that’s part of the problem: there are too many options. Rather than trying to debug your setup, here’s probably the simplest way to get a working lxml on 10.7 using the Apple-supplied system Python 2.7.
You should then be able to use
lxml.etreethis way:I notice though that the
lxmlstatic build process does not produce a working universal build. You’ll probably see messages like this during thelxmlinstall:Assuming the default architecture on your machine is 64-bits, if you try to run in 32-bit mode:
And there is the error message you originally reported! So the root cause of that appears to be that the static libraries (
libxml2etc) thatlxmlbuilds are not universal. As long as you have no need to uselxmlin a 32-bit process (unlikely for most uses), this should not be a problem. Chances are that the Python you were originally using was a 32-bit-only one; that is consistent with some of the other messages you reported.