Written and maintained by CASRAI Editorial Board
Published
On this page
PySAL (the Python Spatial Analysis Library) is an open-source collection of Python packages for spatial data science: it builds spatial weights, tests whether values cluster in space, fits spatial regression models and classifies values for maps. Since version 2.0.0 it is a meta-package that installs a family of affiliated packages rather than one monolithic library, and it supports Python 3 only. This guide maps those packages by layer, shows how to install the current release, walks through a Moran’s I calculation with the arithmetic checked, and explains how to cite the library.
What PySAL is and who uses it
The project’s own manual describes PySAL as “a collection of affiliated geographic data science packages” and groups the work into four areas: explore (exploratory analysis of spatial and spatio-temporal data), viz (visualising patterns, clusters, outliers and hot spots), model (linear, generalised linear, generalised additive and nonlinear spatial models) and lib (the foundation: graph construction, spatial weights, alpha shapes, spatial indices and input/output). It is released under a BSD 3-Clause license, so it can be used inside funded projects, institutional pipelines and teaching material without a licensing fee.
Researchers in geography, planning, public health, criminology, ecology and the social sciences reach for it when a question has a place component: do high values sit next to high values, is a relationship between two variables the same everywhere, how segregated is a city, how unequal is a region. In a research-methods workflow it sits alongside a desktop tool such as GeoDa, which offers a point-and-click route to the same family of exploratory spatial methods, and below a mapping layer described in the guide to geovisualization.
PySAL packages by layer
The project’s GitHub README lists the packages that make up the meta-package, grouped by the same four areas as the manual. The data table below compares each package’s layer, its latest PyPI release and the minimum Python version it declares. Reading it by layer gives the practical order of use: start in lib, analyse in explore, estimate in model, display in viz.
- lib:
libpysalholds the spatial weights classes and the readers and example datasets that every other package builds on. - explore:
esda,giddy,inequality,momepy,pointpats,segregationandspaghetti. Theesdapackage, used in the worked example below, is where global and local spatial autocorrelation statistics live. - model:
mgwr,spglm,spint,spreg,tobler,access,spoptandspml. - viz:
mapclassifyandsplot.
Because the packages are versioned independently, a project should record the version of each package it imports, not only the version of the pysal meta-package. The table shows why: esda and libpysal carry their own release numbers, and not every package declares the same minimum Python version.
How to install PySAL and which Python version it needs
The README gives two routes: conda install pysal from the conda-forge channel, or pip install pysal. On PyPI the current meta-package release is 26.7, uploaded on 31 July 2026, and it declares requires_python >=3.12; the esda (2.10.0) and libpysal (4.15.1) releases carry the same minimum. A researcher on an older interpreter therefore needs a newer environment, or an earlier release pinned in a lockfile.
Python 2 support ended with the 1.x line: the README states that since 2.0.0 PySAL supports Python 3 only and that Python 2 users can install version 1.14.3. Scripts written against the old single-module layout, such as pysal.weights or pysal.esda, generally need their imports changed to the new packages (libpysal.weights, esda).
Worked example: Moran’s I with esda
Moran’s I is the standard global test for spatial autocorrelation, and the esda documentation illustrates it with example data shipped in libpysal. The class signature is Moran(y, w, transformation='r', permutations=999, two_tailed=True), where y is the variable, w a spatial weights object, 'r' row-standardises the weights, and permutations=999 sets the number of random permutations behind the simulated p-value.
import numpy as np
import libpysal
import esda
w = libpysal.io.open(libpysal.examples.get_path("stl.gal")).read()
f = libpysal.io.open(libpysal.examples.get_path("stl_hom.txt"))
y = np.array(f.by_col["HR8893"])
mi = esda.moran.Moran(y, w)
print(mi.I, mi.EI, mi.p_norm)
The documentation reports, for the homicide-rate variable HR8893 on the St. Louis-area contiguity weights, I = 0.244, an expected value EI = −0.012987 and a normal-approximation p-value p_norm = 0.000271. A second documentation example, the SIDR74 variable in the sids2 data, gives I = 0.248 and p_norm = 0.000116.
The expected value can be checked by hand. Under no spatial autocorrelation, E[I] = −1 / (n − 1). Setting −1 / (n − 1) = −0.012987 gives n − 1 = 1 / 0.012987 ≈ 77.0, so the example has n = 78 observations, and −1/77 = −0.012987 matches the reported value. The observed I = 0.244 is therefore about 0.257 above its expectation (0.244 − (−0.012987) = 0.256987), which is what the small p-value of 0.000271 flags as unlikely under randomness. The attributes p_sim and z_sim hold the permutation-based p-value and z-score for the same test. For the statistic’s formula and a hand calculation, see the separate guide to Moran’s I.
Reading the output
| Result | Reading |
|---|---|
| I clearly above E[I] with a small p-value | Similar values tend to be neighbours (positive spatial autocorrelation), as in the 0.244 example |
| I near E[I] (about −1/(n−1)) | No evidence of spatial pattern in this variable under these weights |
| I clearly below E[I] with a small p-value | Dissimilar values tend to be neighbours (negative spatial autocorrelation) |
p_norm versus p_sim disagree |
The normal approximation and the permutation test give different answers; report the permutation value and its number of permutations |
Assumptions and common mistakes
The result of any PySAL autocorrelation test depends on the weights object passed in, so the weights are part of the method, not a technical detail. Choosing contiguity versus distance-based neighbours, or row-standardised versus binary weights, can change I. State the weights type in the methods section and keep the code that built them.
- Treating I as a correlation coefficient. Its expectation under randomness is −1/(n−1), not zero, and it is interpreted against that benchmark.
- Reporting a p-value without saying which one.
p_normandp_simare different procedures; name the one you report and the permutation count. - Ignoring islands. Observations with no neighbours in the weights can distort or block results; inspect the weights object before testing.
- Mixing coordinate systems. Distance-based weights assume sensible projected coordinates; see the guide to pyproj for coordinate transformations.
- Importing old module paths. Code written for PySAL 1.x will not run unchanged on the current release.
- Not recording versions. Package versions differ, as the data table shows; record all of them.
Reporting a PySAL analysis so others can reproduce it
Journals and funders increasingly expect computational methods to be rerunnable, and a spatial analysis has more moving parts than most because the weights, the data projection and the software versions all shape the result. A reproducible PySAL methods paragraph states five things:
- the dataset and its coordinate reference system, including any reprojection applied before distances were computed;
- how spatial weights were built (contiguity or distance, the neighbour definition, whether they were row-standardised) and how islands were handled;
- the statistic and the package that provides it, for example Moran’s I from
esda; - the inference method, whether the normal approximation or a permutation test, with the number of permutations;
- the version of every package imported, from
pip listor a conda environment export, deposited with the code in a repository.
Depositing the script and environment file next to the data lets a reviewer reproduce I, EI and the p-value exactly, which is the same standard applied to the documentation example above.
PySAL compared with GeoDa
PySAL and GeoDa overlap in exploratory spatial data analysis. The practical difference is the interface: PySAL is a scripted library, so the whole analysis, from weights construction to the statistic, can live in version-controlled code that others can rerun, while GeoDa is a desktop application suited to interactive exploration. Many projects explore interactively first and then script the final analysis for reproducibility.
How to cite PySAL
The manual’s recommended citation is Rey and Anselin (2007). In APA 7th style:
Rey, S. J., & Anselin, L. (2007). PySAL: A Python library of spatial analytical methods. Review of Regional Studies, 37(1), 5–27. https://doi.org/10.52324/001c.8285
In the text, cite as (Rey & Anselin, 2007). Also state the version of each package used (for example esda 2.10.0, libpysal 4.15.1) and the date of the installation, since the analysis can depend on them.
Sources
- PySAL manual (pysal.org), read 2026-11-17
- PySAL README, package list and installation (GitHub), read 2026-11-17
- pysal on PyPI: version 26.7, Python requirement and license, read 2026-11-17
- esda.Moran documentation (pysal.org), read 2026-11-17
- Rey, S. J., & Anselin, L. (2007), PySAL: A Python Library of Spatial Analytical Methods, Review of Regional Studies
Data: PySAL meta-package components by layer, latest PyPI release and minimum Python version
The packages listed in the PySAL GitHub README grouped by layer (lib, explore, model, viz), with each package’s latest PyPI release number and declared requires_python value read from the PyPI JSON API on 2026-11-17.
| Package | Layer | Latest PyPI version | Declared Python requirement |
|---|---|---|---|
| libpysal | lib | 4.15.1 | >=3.12 |
| esda | explore | 2.10.0 | >=3.12 |
| giddy | explore | 2.3.9 | >=3.12 |
| inequality | explore | 1.2.0 | >=3.12 |
| momepy | explore | 1.0.0 | >=3.12 |
| pointpats | explore | 2.6.0 | >=3.12 |
| segregation | explore | 2.6.0 | >=3.12 |
| spaghetti | explore | 1.7.6 | >=3.10 |
| mgwr | model | 2.2.1 | >3.5 |
| spglm | model | 1.1.0 | >=3.9 |
| spint | model | 1.1.0 | >=3.12 |
| spreg | model | 1.9.2 | >=3.12 |
| tobler | model | 0.14.0 | >=3.12 |
| access | model | 1.1.10.post3 | >=3.11 |
| spopt | model | 0.8.0 | >=3.12 |
| spml | model | 0.2.2 | >=3.12 |
| mapclassify | viz | 2.11.0 | >=3.12 |
| splot | viz | 1.1.7 |
Sources
- PySAL README (GitHub) (accessed 2026-11-17)
- PyPI JSON API (accessed 2026-11-17)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







