Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use libxml2 with python on macOs?

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
like image 487
John Mee Avatar asked Mar 21 '12 01:03

John Mee


People also ask

Where is libxml2 installed Mac?

OS X comes with libxml2 installed, but it's in /usr/include/libxml2 . So that needs to be added to the include path with a -I/usr/include/libxml2 . The headers contain the definitions of the various functions, but the real code lies in shared libraries.

What is libxml2 python?

The libxml2-python package contains a module that permits applications written in the Python programming language to use the interface supplied by the libxml2 library to manipulate XML files. This library allows to manipulate XML files. It includes support to read, modify and write XML and HTML files.

Is libxml2 Windows installed?

libxml2 is installed by default on MacOSX, but not on Windows systems.


2 Answers

  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?

like image 65
tkone Avatar answered Oct 05 '22 23:10

tkone


tkone's answer is OK. But brew also can do it.

Try this,

  $ brew install libxml2 --with-python
like image 23
jeswang Avatar answered Oct 06 '22 01:10

jeswang