How to use libxml2 with python on macOs?

John Mee picture John Mee · Mar 21, 2012 · Viewed 12.4k times · Source

I'm on OSX Lion and I have libxml2 installed (by default) and I have python installed (by default) but they don't talk to one another. What's the simplest way to make this work on Lion?

$ python -c "import libxml2"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named libxml2

Answer

tkone picture tkone · Mar 21, 2012
  1. Visit ftp://xmlsoft.org/libxml2/python/ and ensure this is the latest version
  2. Download it
  3. unpack it
  4. open a term and cd to that directory
  5. type sudo python setup.py install
  6. ls /Library/Python/2.7/site-packages/ and you should see a bunch of libxml2 files
  7. try the test again and it should work

You'll need XCode installed, but like, you should already have that installed, right?