{"id":8353,"library":"nilearn","title":"Nilearn","description":"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.","status":"active","version":"0.13.1","language":"en","source_language":"en","source_url":"https://github.com/nilearn/nilearn","tags":["neuroimaging","fMRI","machine-learning","brain-imaging","scientific-computing","data-analysis"],"install":[{"cmd":"pip install -U nilearn","lang":"bash","label":"Install latest stable version"},{"cmd":"conda create -n nilearn_env python=3.10\nconda activate nilearn_env\npip install -U nilearn","lang":"bash","label":"Install in a Conda environment"}],"dependencies":[{"reason":"Nilearn requires Python 3.10 or later.","package":"python","optional":false},{"reason":"Required for most plotting functionalities.","package":"matplotlib","optional":false},{"reason":"Core scientific computing dependency.","package":"scipy","optional":false},{"reason":"Used for fetching datasets.","package":"requests","optional":false},{"reason":"A new dependency added in 0.13.0.","package":"jinja2","optional":false},{"reason":"Optional plotting engine for some functions.","package":"plotly","optional":true},{"reason":"Required for static image export with Plotly.","package":"kaleido","optional":true}],"imports":[{"symbol":"datasets","correct":"from nilearn import datasets"},{"note":"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`).","wrong":"from nilearn.plotting.image import plot_img","symbol":"plotting","correct":"from nilearn import plotting"},{"note":"Masker classes like `NiftiMasker` were moved from `nilearn.input_data` to `nilearn.maskers`.","wrong":"from nilearn.input_data import NiftiMasker","symbol":"NiftiMasker","correct":"from nilearn.maskers import NiftiMasker"},{"symbol":"image","correct":"from nilearn import image"},{"symbol":"Decoder","correct":"from nilearn.decoding import Decoder"}],"quickstart":{"code":"import warnings\nwarnings.filterwarnings(\"ignore\", message=\"The provided image has no sform in its header.\")\n\nfrom nilearn import datasets, plotting, maskers\n\n# 1. Fetch a sample fMRI dataset (Haxby dataset)\nhaxby_dataset = datasets.fetch_haxby(subjects=1, fetch_stimuli=False)\nfmri_filename = haxby_dataset.func[0]\nanat_filename = haxby_dataset.anat[0]\nmask_filename = haxby_dataset.mask_vt[0]\n\n# 2. Extract signals using NiftiMasker\n# The mask_strategy='epi' is often more robust for EPI images\nmasker = maskers.NiftiMasker(mask_img=mask_filename, smoothing_fwhm=6, standardize='zscore_sample')\nfmri_data_masked = masker.fit_transform(fmri_filename)\n\n# 3. Plot the anatomical image and overlay the mask\nprint(f\"Shape of masked fMRI data: {fmri_data_masked.shape}\")\n\n# Plotting the anatomical image with the mask overlay\nplotting.plot_anat(\n    anat_filename,\n    title=\"Anatomical image with mask overlay\",\n    display_mode='ortho',\n    cut_coords=(0, 0, 0),\n    output_file=None # Change to a filename like 'anat_with_mask.png' to save\n)\n\n# Plotting a single volume from the fMRI data\nfirst_fmri_volume = image.index_img(fmri_filename, 0)\nplotting.plot_img(\n    first_fmri_volume,\n    bg_img=anat_filename,\n    title=\"First fMRI volume\",\n    display_mode='ortho',\n    cut_coords=(0, 0, 0),\n    output_file=None # Change to a filename like 'first_fmri_volume.png' to save\n)\n\n# You can also show the plots (usually at the end of a script or in an interactive session)\n# plotting.show()","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade Python to 3.10 or higher. For example, using Conda: `conda create -n nilearn_env python=3.10; conda activate nilearn_env`.","message":"Nilearn 0.13.0 dropped support for Python 3.9. Users on Python 3.9 or older versions will encounter installation errors or unexpected behavior.","severity":"breaking","affected_versions":">=0.13.0"},{"fix":"Update import statements: `from nilearn.input_data import NiftiMasker` should become `from nilearn.maskers import NiftiMasker`.","message":"The `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`.","severity":"breaking","affected_versions":">=0.13.0"},{"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')`.","message":"The `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.","severity":"deprecated","affected_versions":">=0.13.0"},{"fix":"Review calls to these dataset fetching functions and explicitly set parameters if you rely on the previous default behaviors.","message":"Default 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`.","severity":"breaking","affected_versions":">=0.13.0"},{"fix":"If you need to maintain the neurological orientation, ensure `radiological=False` is passed to plotting functions that support it.","message":"Plotting 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.","severity":"gotcha","affected_versions":">=0.13.1"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Import the `plotting` module directly and then access functions through it: `from nilearn import plotting; plotting.plot_img(...)`.","cause":"Attempting to import a specific plotting function directly from `nilearn` (e.g., `from nilearn import plot_img`) or from an outdated submodule path (e.g., `from nilearn.plotting.image import plot_img`) after refactoring.","error":"ImportError: cannot import name plotting from 'nilearn'"},{"fix":"Change the import statement to `from nilearn.maskers import NiftiMasker`.","cause":"The `NiftiMasker` class, along with other masker objects, has been moved to the `nilearn.maskers` module.","error":"ImportError: cannot import name 'NiftiMasker' from 'nilearn.input_data'"},{"fix":"Reduce data resolution using `target_affine` and/or `target_shape` parameters in maskers or `nilearn.image.resample_img`. Consider processing fewer subjects at a time or using a server with more RAM. For `NiftiMasker`, explicitly setting `dtype='auto'` can save memory by forcing `float32`.","cause":"Processing large neuroimaging datasets can be memory-intensive, especially during spatial resampling or when working with high-resolution masks without downsampling.","error":"Killed: 9 (or similar out-of-memory errors during masking/resampling)"},{"fix":"Ensure Nilearn is installed via `pip install -U nilearn` (or `conda install nilearn`). Check your current working directory for any files or folders named 'nilearn' that might shadow the installed package.","cause":"Nilearn is not installed in the active Python environment, or there's a naming conflict with a local file/directory named `nilearn.py` or `nilearn`.","error":"ModuleNotFoundError: No module named 'nilearn'"}]}