Model/asset_list
Khalim Conn-Kowlessar 7e9347e530 setting up libpostal
2025-02-19 12:53:09 +00:00
..
tests setting up libpostal 2025-02-19 12:53:09 +00:00
AssetList.py setting up libpostal 2025-02-19 12:53:09 +00:00
README.md setting up libpostal 2025-02-19 12:53:09 +00:00
requirements.txt setting up libpostal 2025-02-19 12:53:09 +00:00

libpostal Installation Guide for macOS M1

Overview

libpostal is a fast, open-source address parsing and normalization library, designed for global addresses. This guide provides detailed steps to install libpostal on macOS with Apple Silicon (M1/M2) and use it with Python.


📌 Prerequisites

Before installing libpostal, ensure you have the necessary dependencies installed.

1 Install Required Dependencies

Open a terminal and run:

brew install curl autoconf automake libtool pkg-config

2 Clone the libpostal Repository

git clone https://github.com/openvenues/libpostal.git
cd libpostal

3 Run Bootstrap Script

./bootstrap.sh

4 Configure the Build (Important for M1 Macs)

Since M1 chips do not support SSE2 natively, you must disable SSE2 for compatibility.

./configure --disable-sse2 --datadir=/usr/local/libpostal_data

(You can replace /usr/local/libpostal_data with another directory that has a few GB of space.)

5 Compile and Install

make -j$(sysctl -n hw.ncpu)
sudo make install

6 Install Python Bindings

Once libpostal is installed, install the Python package:

pip install postal

Verify Installation

To check if libpostal was installed successfully, run:

python -c "import postal; print(postal.parser.parse('23 Clifton Hill, Newtown, Exeter, EX1 2DL'))"

Expected Output:

[('23', 'house_number'), ('Clifton Hill', 'road'), ('Newtown', 'city'), ('Exeter', 'city'), ('EX1 2DL', 'postcode')]

📌 Usage Example in Python

Address Parsing

from postal.parser import parse

address = "23 Clifton Hill, Newtown, Exeter, EX1 2DL"
parsed_address = dict(parse(address))

print(parsed_address)

Expected Output:

{
    'house_number': '23',
    'road': 'Clifton Hill',
    'city': 'Newtown',
    'city': 'Exeter',
    'postcode': 'EX1 2DL'
}

Address Normalization

from postal.normalize import normalize_string

address = "Block (Rooms 1-4), 23 Clifton Hill, Newtown, Exeter, EX1 2DL"
normalized = normalize_string(address)

print(normalized)

📌 Troubleshooting

1 libpostal Not Found?

If you encounter an error like ModuleNotFoundError: No module named 'postal', make sure:

  • You ran sudo make install
  • Your Python environment recognizes postal. Try:
    pip install postal --no-cache-dir
    
  • If using a virtual environment (venv), activate it before running Python.

2 Compilation Issues on macOS?

If make fails, try running:

brew reinstall autoconf automake libtool pkg-config

Then restart the installation process.

3 Can't Find libpostal Data Directory?

Ensure libpostal_data exists in the correct directory:

ls /usr/local/libpostal_data

If missing, re-run ./configure with the correct path.


🛠 Uninstallation

To remove libpostal, run:

sudo rm -rf /usr/local/lib/libpostal*
sudo rm -rf /usr/local/include/libpostal*
rm -rf ~/libpostal
pip uninstall postal

📌 Additional Resources


🎉 Youre all set! Now you can use libpostal to parse and clean address data efficiently. 🚀