# Install pyenv (if not already installed)
# macOS
brew install pyenv
# Install Python 3.11
pyenv install 3.11.9
pyenv local 3.11.9
# Verify installation
python --version # Should show Python 3.11.9
# Install asdf (if not already installed)
# macOS
brew install asdf
# Install Python 3.11
asdf install python 3.11.9
asdf local python 3.11.9
# Verify installation
python --version # Should show Python 3.11.9
brew install python@3.11
sudo apt update
sudo apt install python3.11 python3.11-venv python3.11-pip
Download Python 3.11 from python.org
# Create virtual environment with Python 3.11
python -m venv venv
# Activate virtual environment
source venv/bin/activate # Linux/macOS
# OR
venv\Scripts\activate # Windows
# Verify Python version in venv
python --version # Should show Python 3.11.x
# Install development dependencies
pip install -r requirements.txt
# Verify key packages
python -c "import fastapi, sqlalchemy, pytest, asyncio"
python -c "asyncio.timeout(1.0); print('✅ asyncio.timeout available')"
# Build Docker containers with Python 3.11
docker-compose build
# Start services
docker-compose up -d
# Verify container Python version
docker-compose exec app python --version # Should show Python 3.11.x
Problem: AttributeError: module 'asyncio' has no attribute 'timeout'
Solution: Ensure Python 3.11+ is active. Check with python --version
# Check current Python version
python --version
# If < 3.11, activate correct version
pyenv local 3.11.9 # or asdf local python 3.11.9
source venv/bin/activate # reactivate virtual environment
# Verify fix
python -c "import asyncio; asyncio.timeout(1.0); print('✅ Fixed')"
Problem: Container uses wrong Python version
Solution: Rebuild containers with Python 3.11 base
# Rebuild with no cache
docker-compose build --no-cache
# Verify container Python version
docker-compose exec app python --version # Should show 3.11.x
Problem: GitHub Actions fails with Python version errors
Solution: Workflows now specify Python 3.11 - should auto-resolve
# Check workflow configuration
cat .github/workflows/test.yml | grep "python-version"
# Should show: python-version: '3.11'
Problem: Virtual environment created with wrong Python version
Solution: Delete and recreate with correct Python version
# Remove old virtual environment
rm -rf venv
# Create new with Python 3.11
python3.11 -m venv venv
source venv/bin/activate
# Verify version
python --version # Should show 3.11.x
Problem: Package installation fails with version conflicts
Solution: Ensure clean environment and correct Python version
# Deactivate and reactivate virtual environment
deactivate
source venv/bin/activate
# Upgrade pip
python -m pip install --upgrade pip
# Install dependencies
pip install -r requirements.txt
#!/bin/bash
echo "=== Python Environment Validation ==="
# Check Python version
echo "Python version: $(python --version)"
# Check asyncio.timeout availability
python -c "import asyncio; asyncio.timeout(1.0); print('✅ asyncio.timeout available')"
# Check key dependencies
python -c "import fastapi, sqlalchemy, pytest; print('✅ Key dependencies available')"
# Check virtual environment
if [[ "$VIRTUAL_ENV" != "" ]]; then
echo "✅ Virtual environment active: $VIRTUAL_ENV"
else
echo "⚠️ No virtual environment detected"
fi
echo "=== Validation Complete ==="
#!/bin/bash
echo "=== Docker Environment Validation ==="
# Check container Python version
echo "Container Python version:"
docker-compose exec app python --version
# Check container dependencies
echo "Container dependencies:"
docker-compose exec app python -c "import fastapi, sqlalchemy; print('✅ Container dependencies OK')"
echo "=== Docker Validation Complete ==="
Select Python Interpreter:
Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux)Install Python Extension:
Configure Settings:
{
"python.defaultInterpreterPath": "./venv/bin/python",
"python.linting.enabled": true,
"python.formatting.provider": "black"
}
Configure Project Interpreter:
./venv/bin/pythonConfigure Code Style:
# Install pre-commit hooks
pip install pre-commit
pre-commit install
# Run pre-commit on all files
pre-commit run --all-files
# Run all tests
pytest tests/ -v
# Run specific test categories
pytest tests/services/ -v # Service tests
pytest tests/integration/ -v # Integration tests
# Run with Python 3.11 specific checks
python -W error::DeprecationWarning -m pytest tests/
After completing setup:
If you encounter issues: