This project uses Poetry for Python package management to ensure consistent, reproducible builds across all environments.
- Dependency Resolution: Automatically resolves and locks dependency versions
- Reproducible Builds:
poetry.lockensures identical dependencies across environments - Simplified Management: Single
pyproject.tomlfile for all project metadata - Virtual Environment Management: Automatic virtual environment creation and management
- No More Deployment Issues: Eliminates "works on my machine" problems
Windows:
# Option 1: Using py command (recommended for Windows)
curl -sSL https://install.python-poetry.org | py
# Option 2: Using python command
curl -sSL https://install.python-poetry.org | pythonmacOS/Linux:
curl -sSL https://install.python-poetry.org | python3 -Windows Python Alias Setup (if needed):
- Go to Settings → Apps → App execution aliases
- Turn OFF Python and Python3 aliases if they cause conflicts
poetry self add poetry-plugin-exportpoetry --versiongit clone https://github.com/UBC-CIC/Empathetic-Communication.git
cd Empathetic-CommunicationOnly needed if you want to develop/test locally:
# Install service dependencies for local development
cd cdk/data_ingestion
poetry install
cd ../text_generation
poetry installNote: On Windows, you may see PyMuPDF build errors during poetry install. This is normal and can be ignored - PyMuPDF builds correctly in Docker during deployment.
cd cdk
npm installAfter following the deployment guide, this is all you need for deployment:
cdk deploy --all --parameters EC-Dev-Amplify:githubRepoName=Empathetic-Communication --context StackPrefix=EC-Dev --profile ec-account --require-approval neverThat is all you need to do to deploy the application. Poetry handles everything automatically during Docker builds.
For new team members who just want to deploy:
- Install Poetry:
curl -sSL https://install.python-poetry.org | py(Windows) - Install export plugin:
poetry self add poetry-plugin-export - Clone repo:
git clone https://github.com/UBC-CIC/Empathetic-Communication.git - Install CDK dependencies:
cd cdk && npm install - Follow the deployment guide
- Deploy:
cdk deploy --all --parameters EC-Dev-Amplify:githubRepoName=Empathetic-Communication --context StackPrefix=EC-Dev --profile ec-account --require-approval never
No need to run poetry install anywhere - Docker handles Python dependencies automatically
├── pyproject.toml # Root project dependencies (shared)
├── poetry.lock # Root lock file
├── cdk/
│ ├── data_ingestion/
│ │ ├── pyproject.toml # Data ingestion service dependencies
│ │ ├── poetry.lock # Service-specific lock file
│ │ └── Dockerfile # Uses Poetry for dependency installation
│ └── text_generation/
│ ├── pyproject.toml # Text generation service dependencies
│ ├── poetry.lock # Service-specific lock file
│ └── Dockerfile # Uses Poetry for dependency installation
# Add to specific service
cd cdk/data_ingestion
poetry add package-name
# Add development dependency
poetry add --group dev package-name# Update all dependencies
poetry update
# Update specific package
poetry update package-name
# Update lock file only
poetry lockpoetry remove package-nameOur Dockerfiles use Poetry to install dependencies:
FROM public.ecr.aws/lambda/python:3.11
# Install system dependencies
RUN yum -y install postgresql-devel gcc gcc-c++ libpq make
# Install Poetry
RUN pip install poetry
# Copy Poetry files
COPY pyproject.toml poetry.lock* ${LAMBDA_TASK_ROOT}
# Configure Poetry and install dependencies
WORKDIR ${LAMBDA_TASK_ROOT}
RUN poetry config virtualenvs.create false && \
poetry install --no-root
# Copy source code
COPY src/ ${LAMBDA_TASK_ROOT}
CMD [ "main.handler" ][tool.poetry]
name = "service-name"
version = "0.1.0"
description = "Service description"
[tool.poetry.dependencies]
python = "^3.11"
boto3 = "*"
langchain = "*"
# Use "*" for latest compatible version
# Use "1.24.10" for exact version when needed
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"- Use
"*"for most dependencies - allows Poetry to resolve the best compatible versions - Pin specific versions only when necessary - for packages with known compatibility issues
- Always commit poetry.lock - ensures reproducible builds
- Old requirements.txt files - Kept as backup, but Poetry is now primary
pyproject.toml- Primary dependency definitionpoetry.lock- Locked versions (NEVER delete - ensures reproducible builds)Dockerfile- Now uses Poetry for dependency installation
- CDK builds Docker images
- Docker installs Poetry
- Poetry reads
pyproject.tomlandpoetry.lock - Poetry installs exact dependency versions
- Lambda functions get consistent dependencies
-
Poetry command not found
# Add Poetry to PATH or restart terminal # Windows: Add %APPDATA%\Python\Scripts to PATH # macOS/Linux: Add ~/.local/bin to PATH
-
Dependency conflicts
# Clear cache and reinstall poetry cache clear pypi --all poetry install -
Docker build fails
# Ensure poetry.lock exists poetry lock # Rebuild without cache docker build --no-cache -t service-name .
-
Virtual environment issues
# Remove and recreate environment poetry env remove python poetry install
- Check
poetry.lockexists in service directories - Verify
pyproject.tomlhas correct dependencies - Run
poetry lockto regenerate lock file if needed - Check Docker build logs for specific errors
- Always run
poetry lockafter changing dependencies - Commit both
pyproject.tomlandpoetry.lock - Keep service dependencies isolated in separate directories
- Test Docker builds locally before deployment
For issues with package management:
- Check this documentation
- Review Poetry official docs: https://python-poetry.org/docs/
- Check service-specific
pyproject.tomlfiles - Verify Docker build logs for dependency installation issues
- Ensure
poetry.lockfiles are committed to git