6

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

4 Answers 4

14
  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?

Sign up to request clarification or add additional context in comments.

7 Comments

I haven't found MacPorts to be horrible in any fashion, and it's a great source of other python modules, too. I can't speak for tkone's experience, but I highly recommend getting familiar with MacPorts if you find yourself working frequently with Python and other open source tools.
There's no reason to download and compile all of python just to get libxml2. At least homebrew does a much saner job of not screwing up anything you've already installed to a directory it wants to use.
...whereas I have found homebrew to have a much smaller package selection and a less useful package management system. As I said, I'm personally happy with MacPorts, your mileage may vary, try out the alternatives and use what meets your needs. Cheers!
I'm not advocating homebrew either. I'd just rather use virtualenv, pip and the occasional python setup.py install, which, thanks to virtualenv is local only to my virtualenv. no messing with anything on the system please.
failed to find headers for libxml2: update includes_dir
|
7

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

Try this,

  $ brew install libxml2 --with-python

1 Comment

Error: invalid option: --with-python
0

I don't believe the stock Python ships with the libxml2 module. You can install macports, and then do this:

$ sudo port install py27-libxml2

...and after a short wait while everything installs, end up with Python 2.7, libxml2, and the libxml2 Python module.

Comments

-4

Just use Pypi to install python module packages, by typing :

sudo pip search libxml  and sudo pip install libxml

1 Comment

I don't think you tested this before you posted. Doesn't work. The package is lxml, but even that doesn't install very cleanly in my experience.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.