| description | Set up development environment for mssql-python |
|---|---|
| name | mssql-python-setup |
| agent | agent |
| model | Claude Sonnet 4.5 (copilot) |
You are a development assistant helping set up the development environment for the mssql-python driver.
Help the developer set up their local environment for development. This is typically run once when:
- Cloning the repository for the first time
- Setting up a new machine
- After a major dependency change
- Troubleshooting environment issues
python --version
# or
python3 --versionSupported versions: Refer to pyproject.toml or setup.py (python_requires/classifiers) for the authoritative list. Generally, Python 3.10 or later is required.
| Version | Status |
|---|---|
| 3.10+ (per project metadata) | ✅ Supported |
| 3.9 and below | ❌ Not supported |
which python
# or on Windows
where python
⚠️ Make note of this path - you'll need to ensure your venv uses this Python.
# Check if a venv is already active
echo $VIRTUAL_ENVIf output shows a path → venv is active, skip to Step 2.4 to verify it
If output is empty → No venv active, continue to Step 2.2
# From repository root
python -m venv myvenv
# Or with a specific Python version
python3.13 -m venv myvenv# macOS/Linux
source myvenv/bin/activate
# Windows (Command Prompt)
myvenv\Scripts\activate.bat
# Windows (PowerShell)
myvenv\Scripts\Activate.ps1# Check venv is active
echo $VIRTUAL_ENV
# Expected: /path/to/mssql-python/myvenv
# Verify Python is from venv
which python
# Expected: /path/to/mssql-python/myvenv/bin/python
# Verify Python version in venv
python --version
# Expected: Python 3.10+ pip install --upgrade pippip install -r requirements.txt# Build dependencies
pip install pybind11
# Test dependencies
pip install pytest pytest-cov
# Linting/formatting (optional)
pip install black flake8 autopep8pip install -e .The bulkcopy feature requires mssql_py_core, a Rust-based native module distributed as a NuGet package. It must be installed separately from pip packages.
macOS / Linux:
# From repository root - downloads and extracts the wheel matching your Python/platform
bash eng/scripts/install-mssql-py-core.shWindows (PowerShell):
# From repository root
.\eng\scripts\install-mssql-py-core.ps1ℹ️ The script reads the version from
eng/versions/mssql-py-core.version, downloads the NuGet package from the public Azure Artifacts feed, and extracts themssql_py_core/directory to the repository root.
# Check critical packages
python -c "import pybind11; print('✅ pybind11:', pybind11.get_include())"
python -c "import pytest; print('✅ pytest:', pytest.__version__)"
python -c "import mssql_python; print('✅ mssql_python installed')"
python -c "import mssql_py_core; print('✅ mssql_py_core installed (bulkcopy support)')" 2>/dev/null || echo "⚠️ mssql_py_core not installed (bulkcopy unavailable)"uname -s
# Darwin → macOS
# Linux → Linux
# (Windows users: skip this, you know who you are)cmake --version
# Expected: cmake version 3.15+If missing:
brew install cmakels /opt/homebrew/include/sql.h 2>/dev/null || ls /usr/local/include/sql.h 2>/dev/nullIf missing:
# Install Microsoft ODBC Driver (provides headers for development)
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
ACCEPT_EULA=Y brew install msodbcsql18echo "=== macOS Development Environment ===" && \
cmake --version | head -1 && \
python -c "import pybind11; print('pybind11:', pybind11.get_include())" && \
ls /opt/homebrew/include/sql.h 2>/dev/null && echo "✅ ODBC headers found" || echo "❌ ODBC headers missing"cmake --version
# Expected: cmake version 3.15+gcc --version || clang --versionIf missing (Debian/Ubuntu):
sudo apt-get update
sudo apt-get install -y cmake build-essential python3-devIf missing (RHEL/CentOS/Fedora):
sudo dnf install -y cmake gcc-c++ python3-develIf missing (SUSE):
sudo zypper install -y cmake gcc-c++ python3-develecho "=== Linux Development Environment ===" && \
cmake --version | head -1 && \
gcc --version | head -1 && \
python -c "import pybind11; print('pybind11:', pybind11.get_include())"- Download from: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022
- Run installer
- Select "Desktop development with C++" workload
- This includes CMake automatically
Open Developer Command Prompt for VS 2022 and run:
cmake --version
cl
python -c "import pybind11; print('pybind11:', pybind11.get_include())"
⚠️ Important: Always use Developer Command Prompt for VS 2022 for building, not regular cmd or PowerShell.
⚠️ SECURITY WARNING:
- NEVER commit actual credentials to version control or share them in documentation.
TrustServerCertificate=yesdisables TLS certificate validation and should ONLY be used for isolated local development, never for remote or production connections.
# Set connection string for tests (LOCAL DEVELOPMENT ONLY)
# Replace placeholders with your own values - NEVER commit real credentials!
# Note: Do NOT include Driver= - the driver automatically adds the correct ODBC driver.
export DB_CONNECTION_STRING="SERVER=localhost;DATABASE=testdb;UID=your_user;PWD=your_password;Encrypt=yes;TrustServerCertificate=yes"
# Verify it's set
echo $DB_CONNECTION_STRINGWindows (LOCAL DEVELOPMENT ONLY):
REM Replace placeholders with your own values - NEVER commit real credentials!
REM Note: Do NOT include Driver= - the driver automatically adds the correct ODBC driver.
set DB_CONNECTION_STRING=SERVER=localhost;DATABASE=testdb;UID=your_user;PWD=your_password;Encrypt=yes;TrustServerCertificate=yes💡 Tip: Add this to your shell profile (
.bashrc,.zshrc) or venv'sactivatescript to persist it.
# Append to venv activate script so it's set automatically
echo 'export DB_CONNECTION_STRING="your_connection_string"' >> myvenv/bin/activateCheck if SQL Server container exists:
docker ps -a | grep mssqlIf container exists but is stopped:
docker start mssql-devIf no container exists, create and start one:
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrongPassword123!" \
-p 1433:1433 --name mssql-dev \
-d mcr.microsoft.com/mssql/server:2022-latestVerify container is healthy:
# Check container status
docker ps | grep mssql
# Check SQL Server logs for "ready" message
docker logs mssql-dev 2>&1 | grep "SQL Server is now ready"Useful Docker commands:
# Stop SQL Server container
docker stop mssql-dev
# Start SQL Server container
docker start mssql-dev
# Restart SQL Server container
docker restart mssql-dev
# View SQL Server logs
docker logs -f mssql-dev
# Remove container (will delete data!)
docker rm -f mssql-devmacOS:
SQL Server doesn't run natively on macOS. Use Docker (Option A) or connect to a remote server.
Linux (Ubuntu/Debian):
# Check if SQL Server service is running
sudo systemctl status mssql-server
# Start SQL Server service
sudo systemctl start mssql-server
# Enable auto-start on boot
sudo systemctl enable mssql-server
# Restart SQL Server
sudo systemctl restart mssql-server
# Stop SQL Server
sudo systemctl stop mssql-serverLinux (RHEL/CentOS):
# Check status
sudo systemctl status mssql-server
# Start/Stop/Restart commands are the same as Ubuntu/Debian aboveWindows:
# Check SQL Server service status (PowerShell as Admin)
Get-Service -Name 'MSSQL$*' | Select-Object Name, Status
# Start SQL Server service
Start-Service -Name 'MSSQL$MSSQLSERVER'
# Stop SQL Server service
Stop-Service -Name 'MSSQL$MSSQLSERVER'
# Restart SQL Server service
Restart-Service -Name 'MSSQL$MSSQLSERVER'
# Or use SQL Server Configuration Manager (GUI)No local SQL Server needed. Just ensure:
- Your Azure SQL Database is running
- Firewall rules allow your IP address
- Connection string is correct with proper credentials
Test local SQL Server connection:
sqlcmd -S localhost -U sa -P 'YourPassword' -Q "SELECT @@VERSION"If sqlcmd is not installed:
# macOS (via Homebrew)
brew install sqlcmd
# Linux (Ubuntu/Debian)
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/prod.list)"
sudo apt-get update
sudo apt-get install sqlcmd
# Windows
# Download from: https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-utility# This should connect and list databases
python main.pyExpected output:
...Connection logs...
Database ID: 1, Name: master
Database ID: 2, Name: tempdb
...
Connection closed successfully.
If this fails: See troubleshooting section below.
| Issue | Symptoms | Solution |
|---|---|---|
| SQL Server not running | "Cannot open server", "No connection could be made" | Start SQL Server (see 6.1) |
| Wrong credentials | "Login failed for user" | Check username/password in connection string |
| Port not accessible | "TCP Provider: No connection could be made" | Check firewall, verify port 1433 is open |
| SSL/TLS errors | "SSL Provider: The certificate chain was issued by an authority" | Add TrustServerCertificate=yes to connection string (dev only) |
| ODBC driver missing | "Driver not found" | Install ODBC Driver 18 (see Step 4) |
| Network timeout | Connection times out | Check server address, network connectivity |
# Check if port 1433 is listening (macOS/Linux)
lsof -i :1433
# Or use netstat
netstat -an | grep 1433
# Test port connectivity with telnet
telnet localhost 1433
# Or use nc (netcat)
nc -zv localhost 1433If port 1433 is not listening:
- SQL Server is not running → Start it
- SQL Server is using a different port → Check configuration
- Firewall is blocking the port → Configure firewall
Docker:
docker logs mssql-dev --tail 100Linux:
# View error log
sudo cat /var/opt/mssql/log/errorlog
# View last 50 lines
sudo tail -50 /var/opt/mssql/log/errorlog
# Follow logs in real-time
sudo tail -f /var/opt/mssql/log/errorlogWindows:
C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Log\ERRORLOG
Or use SQL Server Management Studio (SSMS) → Management → SQL Server Logs
# Allow SQL Server through firewall
sudo ufw allow 1433/tcp
# Configure SQL Server to listen on TCP port 1433
sudo /opt/mssql/bin/mssql-conf set network.tcpport 1433
# Enable remote connections
sudo /opt/mssql/bin/mssql-conf set network.tcpenabled true
# Restart SQL Server
sudo systemctl restart mssql-server# Check Docker network
docker network inspect bridge
# Check if container is using the correct port mapping
docker port mssql-dev
# Recreate container with explicit port mapping
docker rm -f mssql-dev
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrongPassword123!" \
-p 1433:1433 --name mssql-dev \
-d mcr.microsoft.com/mssql/server:2022-latest# Get your current IP address
curl -s https://api.ipify.org
# Add this IP to Azure SQL Database firewall rules:
# 1. Go to Azure Portal
# 2. Navigate to your SQL Server
# 3. Settings → Networking
# 4. Add your IP address to firewall rulesRun this comprehensive check:
echo "========================================" && \
echo "Development Environment Verification" && \
echo "========================================" && \
echo "" && \
echo "1. Virtual Environment:" && \
if [ -n "$VIRTUAL_ENV" ]; then echo " ✅ Active: $VIRTUAL_ENV"; else echo " ❌ Not active"; fi && \
echo "" && \
echo "2. Python:" && \
echo " $(python --version)" && \
echo " Path: $(which python)" && \
echo "" && \
echo "3. Key Packages:" && \
python -c "import pybind11; print(' ✅ pybind11:', pybind11.__version__)" 2>/dev/null || echo " ❌ pybind11 not installed" && \
python -c "import pytest; print(' ✅ pytest:', pytest.__version__)" 2>/dev/null || echo " ❌ pytest not installed" && \
python -c "import mssql_python; print(' ✅ mssql_python installed')" 2>/dev/null || echo " ❌ mssql_python not installed" && \
python -c "import mssql_py_core; print(' ✅ mssql_py_core installed (bulkcopy support)')" 2>/dev/null || echo " ⚠️ mssql_py_core not installed (bulkcopy unavailable - run: bash eng/scripts/install-mssql-py-core.sh)" && \
echo "" && \
echo "4. Build Tools:" && \
cmake --version 2>/dev/null | head -1 | sed 's/^/ ✅ /' || echo " ❌ cmake not found" && \
echo "" && \
echo "5. Connection String:" && \
if [ -n "$DB_CONNECTION_STRING" ]; then echo " ✅ Set (hidden for security)"; else echo " ⚠️ Not set (integration tests will fail)"; fi && \
echo "" && \
echo "========================================"Cause: Python < 3.10
Fix:
# Install Python 3.13 (macOS)
brew install python@3.13
# Create venv with specific version
python3.13 -m venv myvenv
source myvenv/bin/activateCause: venv module not installed (some Linux distros)
Fix:
# Debian/Ubuntu
sudo apt-get install python3-venv
# Then create venv
python3 -m venv myvenvCause: Trying to install globally without sudo, or venv not active
Fix:
# Verify venv is active
echo $VIRTUAL_ENV
# If empty, activate it
source myvenv/bin/activate
# Then retry pip install
pip install -r requirements.txtCause: pybind11 installed in different Python than build uses
Fix:
# Check which Python has pybind11
python -c "import pybind11; print(pybind11.get_include())"
# Ensure same Python is used for build
which python
# Reinstall in correct venv if needed
pip install pybind11Fix:
brew install cmake
# Or if Homebrew not in PATH
export PATH="/opt/homebrew/bin:$PATH"Cause: Not using Developer Command Prompt
Fix:
- Close current terminal
- Open Developer Command Prompt for VS 2022 from Start Menu
- Navigate to project and retry
Fix:
# Debian/Ubuntu
sudo apt-get install build-essential
# RHEL/CentOS/Fedora
sudo dnf groupinstall "Development Tools"Cause: Microsoft ODBC Driver not installed
Fix:
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
ACCEPT_EULA=Y brew install msodbcsql18Cause: Network issues, outdated pip, or conflicting packages
Fix:
# Upgrade pip first
pip install --upgrade pip
# Try with verbose output
pip install -r requirements.txt -v
# If specific package fails, install it separately
pip install <package-name>Cause: The mssql_py_core NuGet package has not been installed yet.
Fix:
# macOS/Linux - from repository root
bash eng/scripts/install-mssql-py-core.sh
# Windows (PowerShell) - from repository root
.\eng\scripts\install-mssql-py-core.ps1Cause: PowerShell execution policy
Fix:
# Run PowerShell as Administrator
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Then activate
.\myvenv\Scripts\Activate.ps1# Complete setup from scratch
python3 -m venv myvenv && \
source myvenv/bin/activate && \
pip install --upgrade pip && \
pip install -r requirements.txt && \
pip install pybind11 pytest pytest-cov && \
pip install -e . && \
bash eng/scripts/install-mssql-py-core.sh && \
echo "✅ Setup complete!"| Package | Purpose | Required For |
|---|---|---|
pybind11 |
C++ bindings | Building |
pytest |
Testing | Running tests |
pytest-cov |
Coverage | Coverage reports |
azure-identity |
Azure auth | Runtime (in requirements.txt) |
mssql_py_core |
Rust/TDS bulkcopy core | Bulkcopy feature (via NuGet script) |
Once setup is complete, you can:
- Build DDBC extensions → Use
#build-ddbc(also installsmssql_py_corefor bulkcopy) - Run tests → Use
#run-tests
💡 You typically only need to run this setup prompt once per machine or after major changes.