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
- Install SciPy with one of the commands above, inside an activated environment.
- Import the package. Either keep the name in full or choose an alias:
import scipyorimport scipy as sp. Both give you the same module object; only the local name differs. - Call a submodule function through that name, for example
sp.stats.norm.cdf(0)afterimport scipy as sp, orscipy.stats.norm.cdf(0)afterimport scipy. - Or import the submodule directly, as the documentation suggests:
from scipy import stats, thenstats.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
- SciPy API reference, “Guidelines for importing functions from SciPy”: https://docs.scipy.org/doc/scipy/reference/index.html (checked 2026-10-29)
- Python language reference, the import statement: https://docs.python.org/3/reference/simple_stmts.html#the-import-statement (checked 2026-10-29)
- SciPy installation: https://scipy.org/install/ (checked 2026-10-29)







