Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

import scipy as sp: What the Alias Does and How to Import Submodules

What import scipy as sp does, what the SciPy docs recommend instead, and how to fix the missing-submodule AttributeError.

Written and maintained by CASRAI Editorial Board

Last updated

In Python, import scipy as sp binds the SciPy package to the short name sp. The alias is a community habit, not a requirement: Python gives the module whatever name follows as. The current SciPy documentation itself shows two other forms, import scipy and from scipy import optimize, and this guide explains how the three relate and when each one works best.

What it is used for in research

SciPy supplies numerical routines that many analysis scripts rely on: statistics, optimisation, interpolation, signal processing, sparse matrices and more. Each lives in a submodule such as scipy.stats or scipy.optimize. The import line at the top of a script decides how you refer to those submodules for the rest of it, so it affects readability for collaborators who later reuse or review your code. The alias sp parallels the widely used np for NumPy (see import numpy as np) and plt for Matplotlib (see import matplotlib.pyplot as plt).

What the SciPy documentation recommends

The SciPy API reference has a section called “Guidelines for importing functions from SciPy”. It states that everything in the namespaces of SciPy submodules is public, and it recommends two forms: import scipy followed by calls such as scipy.optimize.curve_fit(...), or from scipy import optimize followed by optimize.curve_fit(...). It does not recommend import scipy as sp in that section. The guidelines also describe lazy loading: submodules are only loaded into memory when you first try to access them.

One exception is named: for scipy.io the documentation prefers import scipy, because io is also the name of a module in the Python standard library. Using import scipy avoids any confusion with that standard-library module.

Install or access

The SciPy installation page gives these official routes. With pip, first create and activate a virtual environment with venv, then run:

python -m pip install scipy

With conda or mamba (the page recommends Miniforge for these):

conda install scipy
mamba install scipy

Step-by-step: import SciPy and call a submodule

  1. Install SciPy with one of the commands above, inside an activated environment.
  2. Import the package. Either keep the name in full or choose an alias: import scipy or import scipy as sp. Both give you the same module object; only the local name differs.
  3. Call a submodule function through that name, for example sp.stats.norm.cdf(0) after import scipy as sp, or scipy.stats.norm.cdf(0) after import scipy.
  4. Or import the submodule directly, as the documentation suggests: from scipy import stats, then stats.norm.cdf(0).

The Python language reference explains the mechanics. If the module name is followed by as, the name after as is bound directly to the imported module. Its example, import foo.bar.baz as fbb, binds fbb to foo.bar.baz and does not bind foo locally. The from form first checks whether the imported module has an attribute of that name, then attempts to import a submodule with that name, and raises ImportError if both fail.

Output and how to read it

A successful import prints nothing. The check is that the name now exists: sp.__name__ returns 'scipy', showing the alias points at the SciPy package. Running print(sp.stats.norm.cdf(0)) returns 0.5, the cumulative probability of a standard normal distribution at zero. See SciPy stats for the statistical routines themselves.

Troubleshooting

module ‘scipy’ has no attribute ‘stats’

This message means the submodule was not loaded when you accessed it through the package name. The current documentation describes lazy loading, where submodules load on first access. If you meet this error, import the submodule explicitly with from scipy import stats, which is the form the guidelines also recommend. Updating SciPy with the install commands above is the other remedy.

ModuleNotFoundError: No module named ‘scipy’

SciPy is not installed in the environment running your script. Activate the environment you installed into, or repeat the install command there.

io clashes with the standard library

Use import scipy and write scipy.io.loadmat(...) rather than from scipy import io, as the SciPy guidelines advise.

A file in your project is named scipy.py

Python resolves an import by name, so a local file with the same name as a package can be found in place of the real one. Rename the file if imports behave unexpectedly.

Free alternatives

These are import styles, all free and all covered by the Python reference or the SciPy guidelines above:

Form Example call Source
import scipy scipy.optimize.curve_fit(...) SciPy importing guidelines
from scipy import optimize optimize.curve_fit(...) SciPy importing guidelines
import scipy as sp sp.optimize.curve_fit(...) Python reference: the name after as is bound to the module
from scipy.stats import distributions distributions.lomax(...) SciPy importing guidelines, for documented public deeper submodules

For worked examples by submodule, see SciPy optimize, SciPy interpolate, SciPy sparse and SciPy signals.

FAQ

Is import scipy as sp required?

No. The name after as is arbitrary and is bound directly to the module. sp is a widespread community alias, but the current SciPy documentation shows import scipy and from scipy import optimize.

Does import scipy as sp load every submodule?

The SciPy guidelines say modules are only loaded in memory when you first try to access them, so importing the package does not load every submodule up front.

Can I use a different alias?

Yes, any valid name works, but using sp or the full name keeps your code recognisable to other researchers.

Which form should I use in shared research code?

The SciPy documentation recommends import scipy or from scipy import followed by a submodule name; whichever you pick, use it consistently across the project.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about import scipy as sp: What the Alias Does and How to Import Submodules

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →