11

Good morning,

I'm trying to install libxml2 with python modules. I have tried the following:

brew install --with-python libxml2                                                                  
==> Downloading ftp://xmlsoft.org/libxml2/libxml2-2.8.0.tar.gz
Already downloaded: /Users/brandon/Library/Caches/Homebrew/libxml2-2.8.0.tar.gz
==> ./configure --prefix=/usr/local/Cellar/libxml2/2.8.0 --without-python

As you can see... even with the --with-python flag, it is still configuring the source without python!

At the end of the install, homebrew says:

Generally there are no consequences of this for you.
If you build your own software and it requires this formula, you'll need
to add its lib & include paths to your build variables:

    LDFLAGS  -L/usr/local/Cellar/libxml2/2.8.0/lib
    CPPFLAGS -I/usr/local/Cellar/libxml2/2.8.0/include

When I try to install the gnome-doc-utils package:

Gnome-doc-utils requires libxml2 to be compiled
with the python modules enabled, to do so:
  $ brew install libxml2 --with-python

So obviously I tried again...

╰─ brew install libxml2 --with-python
Error: libxml2-2.8.0 already installed

I'm still new to this... so any help would be greatly appreciated.

Brandon
  • 3,091
  • 2
  • 34
  • 64
  • Do you have any reason to not use [pip](http://pypi.python.org/pypi/pip/) (or [easy_install](http://packages.python.org/distribute/easy_install.html) as a last resort)? They use to behave much better than other packaging tools - and work with [virtualenv](http://pypi.python.org/pypi/virtualenv/)! – brandizzi Jul 06 '12 at 22:30

4 Answers4

19

First, you cannot install libxml2 because you already successfully installed it, so you will first need to uninstall it.

brew uninstall libxml2

Next you will need to edit the brew formula - which is simple enough to do --

type brew edit libxml2 and change the line

system "./configure", "--prefix=#{prefix}", "--without-python"

to this:

system "./configure", "--prefix=#{prefix}", "--with-python"

This does not fix the problem with the brew formula, but it does force the flag "--with-python", so the next time you type brew install libxml2 it will install the python libraries.

If you need to reset the formula (undo your changes), simply type brew update

kylehuff
  • 5,177
  • 2
  • 34
  • 35
8

This worked for me. First unlink/uninstall if done previously:

brew unlink libxml2
brew unlink libxslt
brew uninstall libxml2
brew uninstall libxslt

Then

brew install --framework python
brew install --with-python libxml2
brew install --with-python libxslt
brew link libxml2 --force
brew link libxslt --force

Voila!

noɥʇʎԀʎzɐɹƆ
  • 9,967
  • 2
  • 50
  • 67
swbandit
  • 1,986
  • 1
  • 26
  • 37
  • 1
    This helped me with fixing some issues I was having with using the lxml parser in Beautifulsoup with a brew installed version of Python so thank you! – Kyle S. Feb 14 '16 at 19:35
  • point of order: brew will complain if you try and uninstall libxml2 *before* libxslt, because the former is required by the latter. Switching the order of the uninstalls worked for me – Christopher Hunter Apr 05 '17 at 19:25
3

What worked for was installing libxml2 with --with-python in brew command

brew install --with-python libxml2
slashmili
  • 1,190
  • 13
  • 16
1

The answer from kylehunt let me fix an issue that some how started to show up after I ran "brew upgrade" after upgrading to macOS Catalina:

If you happen to see things like

Error: libxml2: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:53: syntax error, unexpected <<
<<<<<<< Updated upstream
^~
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:54: syntax error, unexpected ',', expecting end
...              "--with-history",
...                              ^
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:55: syntax error, unexpected ',', expecting end
...            "--without-python",
...                              ^
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:57: syntax error, unexpected ',', expecting end
...               "--with-python",
...

It means you should run

brew edit libxml2

To fix the config file as it might have been broken by merge conflicts during upgrade. Look for <<<<< in the file.