debugpythonMajorpending
Debug: Python script works locally but fails in CI/CD
Viewed 0 times
CI-CDlocal-vs-cienvironmentpathdependenciesversion
Error Messages
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:
# Check CI Python version:
python3 --version
# Match locally: pyenv install 3.11.7 && pyenv local 3.11.7
# In CI config: specify exact version
# Packages with C extensions need system libs
# Add to CI: apt-get install libpq-dev (for psycopg2)
# Or use: pip install psycopg2-binary
# 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
# Don't use relative paths from script location
# Use: Path(__file__).parent / 'data' / 'config.json'
# List what CI provides: env | sort
# Set in CI config or .env file
# CI might be UTC, local might be different
# Always use UTC internally: datetime.now(timezone.utc)
# pip install -r requirements.txt
# Use pip freeze locally, commit exact versions
# Scripts need execute permission: chmod +x script.py
# Git: git update-index --chmod=+x script.py
- 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
- 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
- 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
- Working directory differs:
# Don't use relative paths from script location
# Use: Path(__file__).parent / 'data' / 'config.json'
- Environment variables missing:
# List what CI provides: env | sort
# Set in CI config or .env file
- Timezone differences:
# CI might be UTC, local might be different
# Always use UTC internally: datetime.now(timezone.utc)
- Dependencies not pinned:
# pip install -r requirements.txt
# Use pip freeze locally, commit exact versions
- File permissions:
# Scripts need execute permission: chmod +x script.py
# Git: git update-index --chmod=+x script.py
Revisions (0)
No revisions yet.