3
>>> import lxml
>>> from lxml import etree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python3.4/site-packages/lxml/etree.cpython-34m.so: undefined symbol: __xmlStructuredErrorContext

i do have libxml2 and libxslt, i have tried uninstalling and reinstalling too, it didn't help. lxml version: 3.4.4, python: 3.4.2, OS: RHEL 5.5 Please help resolve this issue

Thanks

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • It's not just a matter of having them, you have to have the same versions that the shared library was compiled against. – Charles Duffy Oct 12 '15 at 20:24
  • BTW, even though the answer given by Regis doesn't fix your immediate problem here, it *is* the better practice to use (as it imports the `etree` module directly, rather than importing the `lxml` module and then resolving its `etree` reference). – Charles Duffy Oct 12 '15 at 20:30
  • BTW, you might find http://stackoverflow.com/questions/26488797/failed-to-linked-symbol-in-so-file-while-the-symbol-exists to be of interest. – Charles Duffy Oct 12 '15 at 20:31

1 Answers1

3

Your version of lxml.etree was compiled against a different version of libxml2 than the one you have actually installed. Reinstalling libxml2 doesn't help because you're just reinstalling the same code. Reinstalling the binaries that bundle your existing etree.cpython-34m.so binary won't work either, because that binary itself is inherently broken (it refers to a symbol that isn't exported in all versions of libxml2).

Uninstall the Python module -- not the C library -- and reinstall it from source. (pip should be able to do this automatically, assuming that you have -devel headers for libxml2 and libxslt installed and an appropriate compiler).

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • Thanks Charles, but i did install lxml using pip. and how do i see how the shared library was compiled against? – Viswajith Kalavapudi Oct 12 '15 at 20:37
  • You might use `ldd` to look up the libxml2 library used by the .so file in question (making sure there's no `LD_LIBRARY_PATH` variable in the environment when your code is invoked at runtime overriding with a different location), and `nm` to look at the symbols it contains. – Charles Duffy Oct 12 '15 at 20:46
  • Thanks Charles, i went through the link and i did the same and here is my error `[root@qos-ucs1 lib]# nm libxml2.so.2 | grep __xmlStructuredErrorContext 00000000000a2750 T __xmlStructuredErrorContext` – Viswajith Kalavapudi Oct 12 '15 at 20:52
  • and i do have a 'T', i am not sure if that is causing the same error – Viswajith Kalavapudi Oct 12 '15 at 20:53
  • Okay -- so your copy of libxml2 in `/usr/lib` **does** export that symbol, so it should work fine. Maybe you have another copy somewhere else? Check LD_LIBRARY_PATH and LD_PRELOAD in your runtime environment to see if they're causing different libraries to be used. – Charles Duffy Oct 12 '15 at 21:02
  • You might also use `strace` to see which files are being loaded at runtime. – Charles Duffy Oct 12 '15 at 21:04