9

I am using Ubuntu 12.04.2 LTS. I have used libxml2 in my python script and when I try to run it, gives error

Traceback (most recent call last):
File "deploy.py", line 3, in <module>
import libxml2
ImportError: No module named libxml2

I tried almost all stackoverflow answers for the same question but nothings solves the issue (Installed several different packages).

the
  • 21,007
  • 11
  • 68
  • 101
Malintha
  • 4,512
  • 9
  • 48
  • 82

3 Answers3

14

You have to install the package in Ubuntu before being able to use it:

sudo apt-get install python-libxml2
enrico.bacis
  • 30,497
  • 10
  • 86
  • 115
  • 5
    i get the message `python-libxml2 is already the newest version (2.9.4+dfsg1-2.2+deb9u2).` and I still get the error: `import libxml2 ImportError: No module named libxml2` - what do I still need to do? – gridtrak Jun 23 '18 at 17:49
1

You'd have to install python-libxml2.

Note that that's a fairly basic wrapper around the libxml2 C library. You may want to use lxml instead, for a far more Pythonic XML API.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

You can try

pip install libxml2-python
Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
  • pip is a python packaging system http://en.wikipedia.org/wiki/Pip_(package_manager) – Anthony Kong Aug 11 '14 at 09:50
  • My apologies, I missed that you were using `pip`. Still, the OP is trying to use the Ubuntu packaging system here. – Martijn Pieters Aug 11 '14 at 09:51
  • 4
    I'm on OSX, so `pip` should be good, but this command gives me `No distributions at all found for libxml2-python`. – the Mar 04 '15 at 12:20
  • Not working, error: ERROR: Could not find a version that satisfies the requirement libxml2-python (from versions: none) ERROR: No matching distribution found for libxml2-python – imankalyan Aug 29 '23 at 11:34
  • Tried "pip install libxml2-python3" that also not working. error: metadata-generation-failed – imankalyan Aug 29 '23 at 11:35