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 S3FS in Python ?
Python is a high-level programming language that has become popular because it is simple to use, and adapt and offers a large range of applications. the process of installing s3fs in Python is simple and involves a few steps. S3FS is used in Python and it is a Pythonic file interface to the S3, This
4 min read
How to install Python in Ubuntu?
This article will guide you through the steps to install Python on Ubuntu, ensuring you're ready to start coding quickly. We will focus on installing Python 3, which is the most widely used version today. Python is typically pre-installed on Ubuntu, particularly Python 3, as it's an essential part o
4 min read
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 libra
2 min read
How to Install Pandas in Python?
Pandas in Python is a package that is written for data analysis and manipulation. Pandas offer various operations and data structures to perform numerical data manipulations and time series. Pandas is an open-source library that is built over Numpy libraries. Pandas library is known for its high pro
5 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 xlrd in Python in Windows?
The xlrd module in python is used to retrieve information from a spreadsheet. In this article, we will look into the process of installing the xlrd module in a Windows machine. Pre-requisites: The only thing that you need for installing the xlrd module on Windows are: PythonPIP or Conda (depending u
2 min read
How to Install Scipy in Python on Windows?
Scipy is a python library that is useful in solving many mathematical equations and algorithms. It is designed on the top of Numpy library that gives more extension of finding scientific mathematical formulae like Matrix Rank, Inverse, polynomial equations, LU Decomposition, etc. Using its high-leve
2 min read
statsmodels.omni_normtest() in Python
With the help of statsmodels.omni_normtest() method, we can get the omnibus test for normality and we use chi^2 score for this statsmodels.omni_normtest() method. Syntax : statsmodels.omni_normtest(array) Return : Return the omnibus test for normality. Example #1 : In this example we can see that by
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 SQLAlchemy in Python on Linux?
SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that is used as flexible database access using SQL. In this article, we will look into the process of installing SQLAlchemy on a windows machine. Pre-requisites: The only thing that you need for installing Numpy on Windows are: Python
2 min read