You can install libxml2 using the following commands:
$ brew install --framework python $ brew install --with-python libxml2 $ brew install --with-python libxslt $ brew link libxml2 --force $ brew link libxslt --force
If you had already installed libxml2 but it had failed or any other error, you can uninstall it and then reinstall it using:
$ brew unlink libxml2 $ brew uninstall libxml2 $ brew unlink libxslt $ brew uninstall libxslt