Registry / ai-ml / nilearn

nilearn

JSON →
library0.13.1pypypiunverified

Nilearn is a Python library for statistical learning with neuroimaging data. It provides tools for general linear model (GLM) based analysis and leverages the scikit-learn toolbox for multivariate statistics, including predictive modeling, classification, decoding, and connectivity analysis. The current stable version is 0.13.1, and releases occur regularly, often including new features, enhancements, and deprecations.

pip install -U nilearn
INSTALL
IMPORT
SIG · NILEARN
N
nilearn
ai-mlpythonv0.13.1
Install
15.9s avg
Import
5491ms
Disk
396MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
build_error
glibc
py 3.103.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()
Debug
Known issues
breakingNilearn 0.13.0 dropped support for Python 3.9. Users on Python 3.9 or older versions will encounter installation errors or unexpected behavior.
fix
Upgrade Python to 3.10 or higher. For example, using Conda: `conda create -n nilearn_env python=3.10; conda activate nilearn_env`.
affects: >=0.13.0
breakingThe `nilearn.input_data` module has been refactored and masker classes (e.g., `NiftiMasker`, `NiftiLabelsMasker`) are now located in `nilearn.maskers`. Direct imports from `nilearn.input_data` will raise an `ImportError`.
fix
Update import statements: `from nilearn.input_data import NiftiMasker` should become `from nilearn.maskers import NiftiMasker`.
affects: >=0.13.0
deprecatedThe `standardize` parameter in various functions and maskers (e.g., `plot_carpet`, `NiftiMasker`) no longer accepts boolean `True`/`False`. Its default behavior changed, and specific string values like `'zscore_sample'` or `None` should be used.
fix
Replace `standardize=True` with `standardize='zscore_sample'` and `standardize=False` with `standardize=None`. For example, `NiftiMasker(standardize=True)` should be `NiftiMasker(standardize='zscore_sample')`.
affects: >=0.13.0
breakingDefault values for parameters in `fetch_atlas_yeo_2011`, `fetch_atlas_craddock_2012`, and `fetch_atlas_smith_2009` have changed in 0.13.0. For instance, `n_networks` and `thickness` in `fetch_atlas_yeo_2011` now default to `7` and `'thick'` respectively, instead of `None`.
fix
Review calls to these dataset fetching functions and explicitly set parameters if you rely on the previous default behaviors.
affects: >=0.13.0
gotchaPlotting functions like `plot_img` now accept a `radiological` parameter (defaulting to `False`) which inverts the x-axis and L/R annotations for radiological convention. If you rely on the old orientation, ensure `radiological=False` is set explicitly.
fix
If you need to maintain the neurological orientation, ensure `radiological=False` is passed to plotting functions that support it.
affects: >=0.13.1
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.
Agent activity
6 hits · last 30 days
node
6
Resources
nilearn — pip install nilearn · libregistry