Install & Compatibility
Where this runs
tested against v0.13.1 · 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.920 runs
build_error
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 15.9s · import 5.491s · 380MB
396MB installed
● package 396MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
datasets
✓ from nilearn import datasets
plotting
✓ from nilearn import plotting
✗ from nilearn.plotting.image import plot_img
Submodules of `nilearn.plotting` like `image` and `surface` were refactored and merged into the main `plotting` module for direct access (e.g., `plot_img` is directly under `nilearn.plotting`).
NiftiMasker
✓ from nilearn.maskers import NiftiMasker
✗ from nilearn.input_data import NiftiMasker
Masker classes like `NiftiMasker` were moved from `nilearn.input_data` to `nilearn.maskers`.
image
✓ from nilearn import image
Decoder
✓ from nilearn.decoding import Decoder
This quickstart fetches the Haxby fMRI dataset, applies a ventral temporal mask, extracts time series data, and then visualizes the anatomical image with the mask overlay and a single fMRI volume. It demonstrates common steps of data loading, masking, and basic visualization.
import warnings
warnings.filterwarnings("ignore", message="The provided image has no sform in its header.")
from nilearn import datasets, plotting, maskers
# 1. Fetch a sample fMRI dataset (Haxby dataset)
haxby_dataset = datasets.fetch_haxby(subjects=1, fetch_stimuli=False)
fmri_filename = haxby_dataset.func[0]
anat_filename = haxby_dataset.anat[0]
mask_filename = haxby_dataset.mask_vt[0]
# 2. Extract signals using NiftiMasker
# The mask_strategy='epi' is often more robust for EPI images
masker = maskers.NiftiMasker(mask_img=mask_filename, smoothing_fwhm=6, standardize='zscore_sample')
fmri_data_masked = masker.fit_transform(fmri_filename)
# 3. Plot the anatomical image and overlay the mask
print(f"Shape of masked fMRI data: {fmri_data_masked.shape}")
# Plotting the anatomical image with the mask overlay
plotting.plot_anat(
anat_filename,
title="Anatomical image with mask overlay",
display_mode='ortho',
cut_coords=(0, 0, 0),
output_file=None # Change to a filename like 'anat_with_mask.png' to save
)
# Plotting a single volume from the fMRI data
first_fmri_volume = image.index_img(fmri_filename, 0)
plotting.plot_img(
first_fmri_volume,
bg_img=anat_filename,
title="First fMRI volume",
display_mode='ortho',
cut_coords=(0, 0, 0),
output_file=None # Change to a filename like 'first_fmri_volume.png' to save
)
# You can also show the plots (usually at the end of a script or in an interactive session)
# plotting.show()
Upgrade
Version history
0.13.1latest on PyPI · released Feb 10, 2026
Audit
Dependencies
pythonrequiredNilearn requires Python 3.10 or later.
matplotlibrequiredRequired for most plotting functionalities.
scipyrequiredCore scientific computing dependency.
requestsrequiredUsed for fetching datasets.
jinja2requiredA new dependency added in 0.13.0.
plotlyoptionalOptional plotting engine for some functions.
kaleidooptionalRequired for static image export with Plotly.