Last Updated: September 26, 2018
·
16.89K
· andrefarzat

Installing libxml2 for python in mac os X

Steps I did to install libxml2 in mac os 10.9:

# install the library using brew
brew install libxml2

# go to python site-packages folder ( in this case, python 2.7 )
cd /Library/Python/2.7/site-packages

# link all python files from site-packages from brew to current python
# ( in this case, libxml2 version is 2.9.1 )
ln -s /usr/local/Cellar/libxml2/2.9.1/lib/python2.7/site-packages/* .

Pay attention to the right site-packages folder if you're using virtualenv.

5 Responses
Add your response

Hi,

It seems like you've manage to install libxml2 without too much trouble. I wish I could do your simple step but as a newby with code lines, I struggle.

I have a mac and it runs os 10.9. I tried to install libxml2, but it seems like a puzzle to solve. There is a lot of programme to install and I don't fully understand. Further explanation would help me a lot.

I've installed macport. I also got the Xcode's and installed them.

I've downloader python and installed it (but I never make it to launch it). Is there other things to do to have the software functional?

I couldn't install the pip (python package manager if I understood). Is it necessary? I don't have the setuptool on python either. Python web page didn't helped me out... I just don't understand where I should enter the command lines. (I repeat that i'm not familiar with code lines).

I dowloaded lxml and libxml... but i don't understand how to install them....

I would be deeply appreciated if you could provide more detail or reference me to a website that give clear informations.

I seeked a lot to find the informations I needed by myself, but as I am a newly with code lines, those pages didn't gave me a clue.

https://pypi.python.org/pypi/pip
http://xmlsoft.org
http://www.explain.com.au/oss/libxml2xslt.html

Thanks in advance for your help and understanding of my situation regarding my computer knowledge. :)

over 1 year ago ·

Hello, @isabellefp,

mac os already comes with python pre-installed, so you should not need to install it again.
Try opening a console and type which python to see if and where it is installed.

To install pip, you can first install easyinstall: https://pypi.python.org/pypi/setuptools#unix-including-mac-os-x-curl
Then you just run `easy
install pip`.

When you installed the xcode, did you also installed the command line tools ?

Macports behaves different from brew in the way that it puts the libraries in another folder and ( I can be wrong ) it needs the sudo to execute/install.

Thus, you should be able to run macports install libxml2, then find where macports installed it and then follow the steps above in the tip to make it work in python.

I hope this helps you =)

over 1 year ago ·

Hi!
Thank you so much!

so I followed the instruction to install pip and I think it worked.

For the Xcode's, I think I also installed the command line tools with the xcode.
Should I try to remove macports or those Xcode's I installed yesterday? (I just want to get the libxml2 in the easiest way, if this brew commas works better, i rather use it)

When I just run the command macports install libxml2, the terminal says that the command not found

and sudo macports install libxml2 gives the same result.

so I still can't install that libxml2

thanks again for your help!!

over 1 year ago ·

Hi, @isabellefp,

so, if the command is not found, for some reason you don't have the macports installed. if you don't mind, try installing brew (http://brew.sh/) and try again =)

over 1 year ago ·

I already have libxml2 installed.
but if you don't:
$ brew install libxml2
And I do these steps and works:
$ brew list libxml2
/usr/local/Cellar/libxml2/2.9.7/bin/xml2-config
/usr/local/Cellar/libxml2/2.9.7/bin/xmlcatalog
/usr/local/Cellar/libxml2/2.9.7/bin/xmllint
/usr/local/Cellar/libxml2/2.9.7/include/libxml2/ (47 files)
/usr/local/Cellar/libxml2/2.9.7/lib/libxml2.2.dylib
/usr/local/Cellar/libxml2/2.9.7/lib/cmake/libxml2/libxml2-config.cmake
/usr/local/Cellar/libxml2/2.9.7/lib/pkgconfig/libxml-2.0.pc
/usr/local/Cellar/libxml2/2.9.7/lib/python2.7/ (4 files)
/usr/local/Cellar/libxml2/2.9.7/lib/ (3 other files)
/usr/local/Cellar/libxml2/2.9.7/share/aclocal/libxml.m4
/usr/local/Cellar/libxml2/2.9.7/share/doc/ (153 files)
/usr/local/Cellar/libxml2/2.9.7/share/gtk-doc/ (55 files)
/usr/local/Cellar/libxml2/2.9.7/share/man/ (4 files)
$ sudo ln -s /usr/local/Cellar/libxml2/2.9.7/lib/python2.7/site-packages/* .
$ irb

require 'nokogiri'
=> true

over 1 year ago ·