Install & Compatibility
Where this runs
tested against v2.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
build_error
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 4.2s · import 0.280s · 123MB
124MB installed
● package 124MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
run_harmony
✓ from harmonypy import run_harmony
✗ from harmonypy.harmony import run_harmony
In v2.0.0, the function has been moved to the top-level package; older versions used a different path.
Harmony
✓ from harmonypy import Harmony
For the class-based API in v2.0.0.
harmonypy
✓ import harmonypy
✗ from harmonypy import harmonypy
Common mistake: trying to import the package name as a module.
Basic harmony batch correction on simulated PCA embeddings.
import numpy as np
import harmonypy
# Simulate data
np.random.seed(0)
Z = np.random.randn(500, 20) # 500 cells, 20 PCs
meta = np.array([0]*250 + [1]*250) # two batches
# Run harmony
ho = harmonypy.run_harmony(Z, meta, ['batch'], max_iter_harmony=10, random_state=0)
corrected = ho.Z_corr
print(corrected.shape)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'harmonypy'
The package is not installed or the Python environment is incorrect.
fixRun `pip install harmonypy==2.0.0` and ensure you are using Python >=3.9.
AttributeError: module 'harmonypy' has no attribute 'run_harmony'
You are using an older version of harmonypy (v0.1.0 or v0.2.0) where the function was located under a different import path or not available.
fixUpgrade to v2.0.0: `pip install harmonypy>=2`. Then use `from harmonypy import run_harmony`.
harmonypy.harmony.Harmony object has no attribute 'Z_corr'
Using old API expecting the old attribute name (e.g., `Z_corrected`) or wrong class.
fixIn v2.0.0, the HarmonyResult object has a `Z_corr` attribute. Refer to the README for current API.
ValueError: The number of cells in meta does not match the number of rows in Z
The `meta` array or DataFrame does not have the same length as the number of cells in the PCA matrix.
fixVerify that meta has exactly the same number of rows as Z (cells).
Upgrade
Version history
2.0.0latest on PyPI · released Apr 26, 2026
Audit
Dependencies
numpyrequiredOnly runtime dependency for v2.0.0 (C++ backend eliminates need for PyTorch/scipy)