<@ULVA73B9P> when deploying using python SDK, usin...
# ask-marvin
p
@Marvin when deploying using python SDK, using default image and getting code from git repo, will requirements from requirements.txt stored in git be installed?
m
thought for 33.3 seconds
Yes, when you deploy a flow from a Git repository using the Python SDK with the default Docker image, any requirements listed in your
requirements.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:
Copy code
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.
p
@Marvin what about when using push=False and build=False? When prefect docker image will be used and no new image will be built
m
thought for 45.3 seconds
Ah, this is an important distinction I should clarify: When using
push=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:
Copy code
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.