January 2026
This guide shows you how to build
KaHyPar’s
Python bindings from source and manually installing the resulting shared library into
Python’s site-packages.
It works on an Apple M4 Pro chip with Python 3.12.8.
Clone the repository with required submodules.
git clone --depth=1 --recursive https://github.com/kahypar/kahypar.git
Move into the repository directory.
cd kahypar
KaHyPar uses an out-of-tree build layout.
mkdir -p build
cd build
Enter the Python build directory and compile the module.
cd python
make
After building, a shared object (.so) file should be present.
ls -lh *.so
cpython-312 in the name).
Use the exact .so filename you see here in the copy step below.
Determine where Python installs packages.
SITEPKG=$(python -c "import site; print(site.getsitepackages()[0])")
Copy the compiled shared library into site-packages.
cp kahypar*.so "$SITEPKG/kahypar.so"
kahypar*.so you built into site-packages under the stable name
kahypar.so, so import kahypar works consistently.
If multiple matches exist, copy the specific file name instead of using the wildcard.
cd ../../../
Check that Python can successfully import KaHyPar.
python -c 'import kahypar; print("Success! Attributes:", [x for x in dir(kahypar) if not x.startswith("_")])'
python and make target the same Python version.SITEPKG should point inside that environment..so is Python-version-specific).