How to use libxml2 with python on macOs?
12,797
Solution 1
- Visit ftp://xmlsoft.org/libxml2/python/ and ensure this is the latest version
- Download it
- unpack it
- open a term and cd to that directory
- type
sudo python setup.py install
-
ls /Library/Python/2.7/site-packages/
and you should see a bunch of libxml2 files - try the test again and it should work
You'll need XCode installed, but like, you should already have that installed, right?
Solution 2
tkone's answer is OK. But brew also can do it.
Try this,
$ brew install libxml2 --with-python
Comments
-
John Mee almost 2 years
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
-
larsks about 12 yearsI 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.
-
tkone about 12 yearsThere'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.
-
larsks about 12 years...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!
-
tkone about 12 yearsI'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. -
Kien Truong about 12 yearsFor package in pypi, you don't even need to manually download, unzip and run
python setup.py install
. Justpip install
in virtualenv and you're done. -
tkone about 12 yearsI had tried pip but just pip install libxml didn't work and I was too lazy to search for it :)
-
Gattster over 10 yearsI 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.
-
Rodrigo Vieira about 5 yearsfailed to find headers for libxml2: update includes_dir
-
Rodrigo Vieira about 5 yearsError: invalid option: --with-python