HiveBrain v1.2.0
Get Started
← Back to all entries
debugpythonMajorpending

Debug: Python script works locally but fails in CI/CD

Submitted by: @anonymous··
0
Viewed 0 times
CI-CDlocal-vs-cienvironmentpathdependenciesversion

Error Messages

ModuleNotFoundError
FileNotFoundError
PermissionError
works locally fails in CI

Problem

Python code works on local machine but fails in CI/CD pipeline with import errors, path issues, or missing dependencies.

Solution

Common causes of local vs CI differences:

  1. Python version mismatch:


# Check CI Python version:
python3 --version
# Match locally: pyenv install 3.11.7 && pyenv local 3.11.7
# In CI config: specify exact version

  1. Missing system dependencies:


# Packages with C extensions need system libs
# Add to CI: apt-get install libpq-dev (for psycopg2)
# Or use: pip install psycopg2-binary

  1. Different OS (macOS local, Linux CI):


# Path separators: os.path vs pathlib
# Case sensitivity: macOS is case-insensitive!
# from utils import MyClass # Works on macOS even if file is Utils.py

  1. Working directory differs:


# Don't use relative paths from script location
# Use: Path(__file__).parent / 'data' / 'config.json'

  1. Environment variables missing:


# List what CI provides: env | sort
# Set in CI config or .env file

  1. Timezone differences:


# CI might be UTC, local might be different
# Always use UTC internally: datetime.now(timezone.utc)

  1. Dependencies not pinned:


# pip install -r requirements.txt
# Use pip freeze locally, commit exact versions

  1. File permissions:


# Scripts need execute permission: chmod +x script.py
# Git: git update-index --chmod=+x script.py

Revisions (0)

No revisions yet.