Two ways to install LexNLP: (1) a naked pip install lexnlp into whatever Python you have handy, or (2) a clean Python 3.8 virtual environment with the exact pinned dependencies. The second one is boring. It’s also the only one that works reliably.
Here’s why that matters in practice. LexNLP 2.3.0 hard-pins 24 dependencies in its setup.py – numpy==1.23.4, pandas==1.5.1, scipy==1.9.3, scikit-learn==0.24. Drop that into Python 3.11 and pip will fail to build wheels. Drop it into a shared Python 3.8 env you already use for other projects and those pinned versions will silently overwrite whatever you had. Either way: pain. Isolated venv, Python 3.8 or 3.9, no exceptions.
What LexNLP 2.3.0 actually is (30 seconds)
LexNLP is a Python library from LexPredict for extracting structured data from contracts, policies, and other unstructured legal text. Version 2.3.0 shipped November 30, 2022 – the 13th release on PyPI since the project launched in April 2019 (per libraries.io). Built primarily on NLTK, with optional pieces from Stanford NLP, gensim, and spaCy (per the official docs).
License: dual AGPLv3 by default, commercial license on request from ContraxSuite. AGPL has a network-use clause – if your product is user-accessible over a network, you’d need to release your source code. Building a SaaS legal tool? That almost certainly triggers it. Contact ContraxSuite Licensing (email in their README) before shipping. Research or open-source work? AGPL is fine.
System requirements
| Component | Minimum | Recommended |
|---|---|---|
| OS | Ubuntu 20.04 / macOS 11 / Windows 10 with Build Tools | Ubuntu 22.04 or macOS 12+ |
| Python | 3.8 | 3.8 (the README says 3.8; 3.9 works with occasional deprecation warnings; 3.10+ fights the pinned deps) |
| RAM | ~4 GB (estimated) | ~8 GB+ (word-embedding models load hot) |
| Disk | ~2 GB free (estimated) | ~5 GB (NLTK data + gensim models expand fast) |
| Build tools | gcc + LAPACK/BLAS on Linux; Visual C++ 14.0 on Windows | Same |
The Python 3.8 requirement comes straight from the official README, which lists Python 3.8 and pipenv as the tested toolchain. RAM and disk figures above are estimates based on typical NLTK + gensim footprints – your mileage will vary.
Install: the clean-venv path
Run this top to bottom. Don’t skip the venv step.
# 1. Create an isolated Python 3.8 venv
python3.8 -m venv lexnlp-env
source lexnlp-env/bin/activate # Windows: lexnlp-envScriptsactivate
# 2. Upgrade pip inside the venv (old pip mishandles pinned deps)
pip install --upgrade pip setuptools wheel
# 3. Install LexNLP 2.3.0 from PyPI
pip install lexnlp==2.3.0
# 4. Download NLTK data that LexNLP needs at runtime
python -m nltk.downloader punkt averaged_perceptron_tagger wordnet stopwords maxent_ne_chunker words
Step 4 is the one every tutorial skips. NLTK data is not bundled with pip installs – the official NLTK docs confirm this. Skip it and your first extraction call throws LookupError: Resource punkt not found. No warning, no graceful fallback, just a crash.
Behind a corporate proxy? The NLTK downloader will hang silently. The fix: run python -m nltk.downloader -d ~/nltk_data punkt on a machine with open internet, then copy the nltk_data folder over manually. Takes an extra five minutes but beats debugging a hanging process for an hour.
Alternative: install from source (for developers)
git clone https://github.com/LexPredict/lexpredict-lexnlp.git
cd lexpredict-lexnlp
pipenv install --python 3.8
pipenv shell
Source path only makes sense if you’re patching the code. For everyone else, the PyPI wheel is faster.
Verify the install
Two checks. Version first, then an actual extraction.
python -c "import lexnlp; print(lexnlp.__version__)"
# Should print: 2.3.0
python -c "from lexnlp.extract.en.money import get_money; print(list(get_money('The buyer shall pay $2,500,000 USD.')))"
# Should print a list containing a monetary extraction tuple
Both return without a traceback? Done. Second one throws LookupError? Go back and run the NLTK downloader from step 4.
One more thing to watch for: the first import of lexnlp.extract.en.dates can take 10-20 seconds. That’s regex compilation on first load – observed behavior, not officially documented. It caches after that first run, so subsequent imports are fast. Not a bug, just surprising the first time.
Common errors and real fixes
Each of these maps to an open or closed issue on the LexPredict GitHub tracker.
- Windows:
Failed building wheel for pandas– Turns out the error text sometimes mentionsgcc, which sends you down the wrong path. The actual fix on Windows is Visual Studio Build Tools 2019 or later with the C++ workload installed (reported in issue #11 on the GitHub tracker). No gcc involved. - Linux:
no lapack/blas resources found– scipy is trying to compile from source because no matching wheel exists for your Python version. Fix on Ubuntu:sudo apt install libatlas-base-dev gfortran liblapack-dev, then retry pip. Documented in issue #37. Could not find a version that matches urllib(pipenv) – old pipenv resolver conflicting with LexNLP’s constraints. Upgrade pipenv (pip install --upgrade pipenv) or fall back to plain pip + venv.- scikit-learn==0.24 / numpy==1.23.4 on Python 3.11+ – these pinned versions (in
setup.py) predate Python 3.11’s build changes. Wheels fail to install or fail to import. Python 3.8 or 3.9 only.
The shared-venv trap
Installing LexNLP into a venv you share with other projects is asking for trouble. The hard-pinned install_requires in setup.py will overwrite newer versions of pandas, numpy, and scikit-learn that your other code depends on. You won’t get a warning – pip just downgrades silently and your other project breaks on next run.
The fix is the same as the install fix: dedicated venv per project. LexNLP’s deps are old enough that they’re incompatible with most modern Python stacks, so isolation isn’t optional here, it’s the whole strategy.
Upgrade and uninstall
Upgrading from 2.2.x? The pinned deps are close enough that it often works. The safer move is still to nuke and rebuild:
# Uninstall
pip uninstall lexnlp
# Or blow away the whole venv (recommended)
deactivate
rm -rf lexnlp-env/
# Then re-create with the clean-venv path from earlier
The NLTK data at ~/nltk_data survives uninstalls. Delete that folder manually if you want a clean slate – it can grow to 3+ GB if you downloaded everything.
Before you ship: the maintenance signal
LexNLP’s release cadence has slowed. Version 2.3.0 was the most recent release as of early 2023, and since then the public repo has been quiet. The community fork openlegal-lexnlp appeared on PyPI in December 2022 – a sign that some users are hedging against upstream stagnation. For a proof-of-concept, 2.3.0 is fine. For a production system you’ll maintain for years, factor in the AGPL question and the maintenance signal now, not later. No official Docker image exists for the standalone library as of the 2.3.0 release – LexPredict ships a Dockerized deployment only for the full ContraxSuite platform.
FAQ
Does LexNLP work with Python 3.11 or 3.12?
No. scikit-learn==0.24 and numpy==1.23.4 – both pinned in setup.py – don’t build cleanly on Python 3.11+. Use Python 3.8.
Can I use LexNLP commercially without paying LexPredict?
AGPLv3 allows it technically, but the network-use clause is the catch. If users access your service over a network – say, a SaaS contract review tool – AGPL likely requires you to publish your source code. That’s a real constraint for most commercial products. ContraxSuite Licensing offers a commercial evaluation license; the contact email is in the GitHub README. If the stakes are high, get a lawyer to review before you ship.
Is there an official Docker image?
No standalone image on Docker Hub as of the 2.3.0 release. Roll your own: Python 3.8-slim base, the four install commands above, done.
Next action: Open a terminal, create lexnlp-env with Python 3.8, run the four commands in the install section, then paste the money-extraction verify snippet. Fifteen minutes end to end.