Skip to content

SciPy - Environment Setup

To use SciPy, you first need a working Python installation (Python 3.7 or newer is recommended for modern SciPy versions). SciPy itself is a package that needs to be installed into your Python environment.

It’s highly recommended to use a virtual environment to manage your project dependencies. Python’s built-in venv module or Conda environments are excellent choices.

pip is the standard package installer for Python. If you have Python and pip installed, you can install SciPy from the Python Package Index (PyPI) by running the following command in your terminal or command prompt:

# Create and activate a virtual environment (recommended)
# python -m venv my_scipy_env
# source my_scipy_env/bin/activate # On Linux/macOS
# .\my_scipy_env\Scripts\activate # On Windows
pip install scipy

This command will download and install SciPy along with its primary dependency, NumPy, if it’s not already present. To install a specific version:

pip install scipy==1.10.0 # Example: install SciPy version 1.10.0

Anaconda (https://www.anaconda.com/products/distribution) and Miniconda (https://docs.conda.io/en/latest/miniconda.html) are popular Python distributions that come with the conda package manager. Conda makes managing packages and environments, especially for scientific computing, very convenient.

To install SciPy in a Conda environment:

# Create a new conda environment (optional, but recommended)
# conda create --name my_scipy_env python=3.9
# conda activate my_scipy_env
conda install scipy

Conda often installs packages from the anaconda channel by default, which usually provides pre-compiled binaries optimized for various systems. You can also specify other channels, like conda-forge:

conda install -c conda-forge scipy

On Linux distributions, you can often install SciPy using the system’s package manager. However, these versions might not always be the latest. Using pip or conda in a virtual environment is generally preferred for better control over package versions.

sudo apt-get update
sudo apt-get install python3-scipy

(This will install SciPy for the system’s Python 3. You might also need python3-numpy, python3-matplotlib, etc., for a full scientific stack.)

sudo dnf install python3-scipy

After installation, you can verify that SciPy is correctly installed by opening a Python interpreter and trying to import it:

python
>>> import scipy
>>> print(scipy.__version__)
# This should print the installed SciPy version, e.g., 1.10.1

If the import is successful and the version is printed without errors, SciPy is ready to use.

SciPy depends heavily on NumPy for its N-dimensional array objects and fundamental numerical operations. When you install SciPy, NumPy is automatically installed if not already present.

For certain functionalities or for following along with many tutorials (including plotting results), you might also want to install other packages in the scientific Python ecosystem:

  • Matplotlib: For plotting and visualization (pip install matplotlib).
  • Pandas: For data manipulation and analysis, especially with tabular data (pip install pandas).
  • scikit-learn: For machine learning (pip install scikit-learn).
  • scikit-image: For advanced image processing (pip install scikit-image).
  • IPython/Jupyter: For an enhanced interactive Python experience and notebooks (pip install ipython jupyter).

A common way to get a comprehensive scientific Python environment is to install the Anaconda distribution, which bundles most of these packages.