| title | Install mssql-python |
|---|---|
| description | Learn how to install the mssql-python driver on Windows, Linux, and macOS. No external ODBC driver is required. |
| author | dlevy-msft-sql |
| ms.author | dlevy |
| ms.date | 07/24/2026 |
| ms.service | sql |
| ms.subservice | connectivity |
| ms.topic | how-to |
| ai-usage | ai-assisted |
The mssql-python driver is Microsoft's official Python driver for SQL Server, Azure SQL Database, Azure SQL Managed Instance, and SQL database in Microsoft Fabric. Install the driver on Windows, Linux, or macOS by using pip.
- The driver requires Python 3.10 or later and doesn't support earlier Python versions.
- pip package manager (included with Python 3.4+).
Important
The mssql-python driver uses DDBC (Direct Database Connectivity), which bundles and manages the ODBC layer internally. You don't need to install the Microsoft ODBC Driver for SQL Server separately.
Install the driver using pip:
pip install mssql-pythonTo upgrade an existing installation:
pip install --upgrade mssql-pythonTo install a specific version:
pip install mssql-python==1.12.0After installation, verify the driver is working:
import mssql_python
print(f"mssql-python version: {mssql_python.__version__}")
print(f"DB-API level: {mssql_python.apilevel}")
print(f"Thread safety: {mssql_python.threadsafety}")
print(f"Parameter style: {mssql_python.paramstyle}")Expected output:
mssql-python version: 1.12.0
DB-API level: 2.0
Thread safety: 1
Parameter style: pyformat
The driver ships as a prebuilt wheel that includes all necessary components.
The driver requires certain system libraries for Kerberos authentication and dynamic loading. Install them using your distribution's package manager:
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install libltdl7 libkrb5-3 libgssapi-krb5-2Red Hat/CentOS/Fedora:
sudo dnf install libtool-ltdl krb5-libsNote
On RHEL 8 and other glibc 2.28 compatible distributions (AlmaLinux 8, Rocky Linux 8), the driver installs from the standard manylinux_2_28 wheel published to PyPI.
Alpine Linux:
apk add libltdl krb5-libsThe driver ships as a universal2 fat binary that runs natively on both Apple Silicon (arm64) and Intel (x86_64) Macs. You don't need a separate unixODBC install.
The driver requires OpenSSL. Install it by using Homebrew:
brew install opensslIf you encounter SSL-related errors, ensure OpenSSL is properly linked:
export LDFLAGS="-L/opt/homebrew/opt/openssl/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl/include"To avoid conflicts, install Python packages in a virtual environment:
# Create a virtual environment
python -m venv .venv
# Activate it (Windows)
.venv\Scripts\activate
# Activate it (Linux/macOS)
source .venv/bin/activate
# Install the driver
pip install mssql-pythonTo install the driver with development dependencies for contributing to the driver:
git clone https://github.com/microsoft/mssql-python.git
cd mssql-python
pip install -e ".[dev]"Ensure you're using Python 3.10 or later:
python --versionIf you're using an older Python version, upgrade Python or use pyenv to manage multiple versions.
If you see ModuleNotFoundError: No module named 'mssql_python', verify you're using the same Python environment where you installed the package.
pip show mssql-pythonIf you encounter permission errors, avoid using sudo pip. Instead, use a virtual environment or the --user flag.
pip install --user mssql-python