Piotr
07/01/2025, 4:01 PMMarvin
07/01/2025, 4:01 PMMarvin
07/01/2025, 4:02 PMrequirements.txt
file will be automatically installed. This happens during the Docker image build process - Prefect's default Dockerfile configuration copies your project files (including requirements.txt) into the image and installs the dependencies.
Here's a typical deployment setup that demonstrates this behavior:
python
from prefect import flow
from prefect.deployments import Deployment
@flow
def my_flow():
# your flow code here
pass
deployment = flow.from_source(
source="<https://github.com/your-username/your-repo>",
entrypoint="path/to/flow.py:my_flow"
).deploy(
name="my-deployment",
work_pool_name="my-docker-pool"
)
As long as your requirements.txt
file is in the root of your Git repository, Prefect will automatically handle the installation of those dependencies when building the Docker image for your deployment.
You can find more details about Docker-based deployments in the Docker infrastructure guide and deployment via Python guide.Piotr
07/01/2025, 4:03 PMMarvin
07/01/2025, 4:03 PMMarvin
07/01/2025, 4:04 PMpush=False
and build=False
with the default Prefect Docker image, the requirements from your requirements.txt
will NOT be automatically installed. This is because:
1. You're using the pre-built Prefect base image directly
2. No Docker build process occurs (due to build=False
)
3. The base image only includes Prefect and its core dependencies
In this scenario, you'll need to handle dependencies in one of these ways:
1. Install the requirements at runtime using a flow.with_options()
setup:
python
@flow
def my_flow():
pass
deployment = flow.from_source(
source="<https://github.com/your-username/your-repo>",
entrypoint="path/to/flow.py:my_flow"
).with_options(
job_configuration={
"pip_packages": ["package1", "package2"] # or reference requirements.txt
}
).deploy(
name="my-deployment",
work_pool_name="my-docker-pool",
build=False,
push=False
)
2. Use a pre-built custom image that already includes all your requirements
3. Switch to build=True
to allow Prefect to handle the requirements installation during image building
The first option (runtime installation) will work but may add overhead to each flow run. For production environments, using a pre-built image with all dependencies included (option 2) or allowing Prefect to build a custom image (option 3) would be more efficient.