How to Install Statsmodels in Python?
Last Updated :
31 Jan, 2025
Statsmodels is a Python library that enables us to estimate and analyze various statistical models. It is built on numeric and scientific libraries like NumPy and SciPy. It provides classes & functions for the estimation of many different statistical models.
Before installing Statsmodels, ensure that you have:
- Python installed (version 3.x recommended)
- pip (Python package manager) installed
- A virtual environment (optional but recommended for better package management)
Installing Statsmodels in Windows
1. Installing Statsmodels using pip
The easiest way to install Statsmodels is by using pip. Run the following command in your terminal or command prompt:
python -m venv env
.\env\Scripts\activate
pip install statsmodels
This will automatically install Statsmodels with its dependencies including NumPy, SciPy, Pandas, and Patsy. Patsy is used for handling formulas in statistical models.
2. Installing Statsmodels via Conda (Anaconda Users)
If you use Anaconda, you can install Statsmodels using the Conda package manager:
conda install -c conda-forge statsmodels
To continue with installation type 'y':
We have successfully installed statsmodel library.
Verifying the Installation
After installation, you can verify that Statsmodels is working correctly by running the following Python script:
Python
import statsmodels.api as sm
print("Statsmodels version:", sm.__version__)
Output
Statsmodels version: 0.14.4
Installing Statsmodels in Linux
1. Installing Statsmodels using pip
Follow the below steps to install statsmodels in Python on Linux using pip:
$ python3 -m venv StatsM
$ source ./StatsM/bin/activate
$ pip install statsmodels
Hence, installation is successful.
2. Installing Statsmodels using conda
To install Statsmodels in Python on Linux using Conda, follow these steps:
Step 1: Download and Install Miniconda
- Create a directory for Miniconda installation and download the Miniconda installer using the following commands:
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
- Run the Miniconda installer to install Miniconda and remove the installer script:
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh
Step 2: Activate the Conda Base Environment using following command:
source ~/miniconda3/bin/activate
Note: The (base) in the terminal prompt indicates that you have successfully entered the Conda environment. The base Conda environment is now active. You can install, manage, or run packages within this environment. Any Python commands executed will use the Conda-installed Python and dependencies.
Verify the active Conda environment by running:
conda info --envs
Step 3: Install Statsmodels in the Conda environment using the following command:
conda install -c conda-forge statsmodels
This will display the installed version of Statsmodels, confirming that the installation was successful.
Step 4: Verify the Installation of Statsmodels by running the following command:
import statsmodels.api as sm
print(sm.__version__)
By following these steps, you can successfully install Statsmodels in a Conda environment on Linux.
Similar Reads
How to Install Python sympy in Windows? Sympy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python. SymPy only depends on mpmath, a pure Python libr
2 min read
How To Install Seaborn In Pycharm? Seaborn is a popular Python data visualization library that is based on the Matplotlib library. You can create informative designs and attractive statistical graphics. Data analysts and scientists can more easily display their data with Seaborn high-level interface. They can easily construct differe
4 min read
How to Install Scipy in Python on Windows? SciPy is a Python library used for scientific and technical computing. It builds on NumPy and provides modules for optimization, integration, interpolation, eigenvalue problems, and more. Before using SciPy in your Python project on Windows, you need to install it properly.Depending on your environm
1 min read
How to Install sqlalchemy in Python on MacOS? In this article, we will learn how to install SQLAlchemy in Python on MacOS. SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL Installation:Method 1: Using pip to install SQLAlchemy Follow the below steps to inst
2 min read
How to Install Scipy In Python on Linux? SciPy is an open-source Python library used for scientific and technical computing. It builds on NumPy and provides a wide range of functions for linear algebra, optimization, integration, statistics and signal processing. If using Linux for Python development, installing SciPy is an important step
2 min read
How to Install Scipy in Python on MacOS? SciPy is a popular open-source Python library for scientific computing, built on NumPy. It offers modules for optimization, linear algebra, integration, signal and image processing, statistics and more. If you're using macOS for Python development or data science, installing SciPy is an essential st
2 min read