Skip to content

Instantly share code, notes, and snippets.

@jmrnilsson
Last active November 16, 2022 13:01
Show Gist options
  • Save jmrnilsson/d51a1172ffba6c4b424d25db4f061e40 to your computer and use it in GitHub Desktop.
Save jmrnilsson/d51a1172ffba6c4b424d25db4f061e40 to your computer and use it in GitHub Desktop.
Installing lxml in 2022 on MacOS 12.6 Monterrey
  1. Upgrade pip globally and in virtualenv and build deps
pip install --upgrade pip
source ./.venv/bin/activate
pip install --upgrade pip
pip install setuptools
deactivate
brew install libxml2
brew install libxslt
  1. Link libraries
echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.zshrc   
export LDFLAGS="-L/usr/local/opt/libxml2/lib"      
export CPPFLAGS="-I/usr/local/opt/libxml2/include"    
echo 'export PATH="/usr/local/opt/libxslt/bin:$PATH"' >> ~/.zshrc        
export LDFLAGS="-L/usr/local/opt/libxslt/lib" 
export CPPFLAGS="-I/usr/local/opt/libxslt/include" 
  1. Build
source ./.venv/bin/activate
pip install lxml --install-option="--libxml2-version=2.9.2"

References After checking many different answers for this post eventually I came across these important ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment