Report this

What is the reason for this report?

How do I add requirements.txt to Digital Ocean's Serverless Functions? Runtime Python:3.11 does not have all the libraries I need Installed

Posted on August 25, 2025

I’m attempting to deploy a serverless functions package to Digital Ocean’s functions namespace. The issue is that I can deploy it without problem when I stay within the Python 3.11 libraries. But as soon as I need another library (not within this runtime), my function fails.

Here’s the steps I’ve taken:

  1. Set up the git repo directory as prescribed by Digital Ocean’s docs (https://docs.digitalocean.com/products/functions/how-to/create-functions/)
example-project/
├── lib
|   └── common
│       └── __init__.py
|       └── static.py
│   └── __init__.py
├── packages
│   └── samples
│       └── func1
│           └── __main__.py
│           └── __init__.py
│           └── .include
│           └── requirements.txt
|       └── func2
│           └── __main__.py
│           └── __init__.py
│           └── .include
│           └── requirements.txt
|       └── func3
│           └── __main__.py
│           └── __init__.py
│           └── .include
│           └── requirements.txt
└── project.yml
└── .env
└── .gitignore
  1. Set up the project.yml like this:
targetNamespace: "fn-************"
environment:
  ENV: production
  DO_SPACES_ACCESS_KEY: "${DO_SPACES_ACCESS_KEY}"
  DO_SPACES_SECRET_KEY: "${DO_SPACES_SECRET_KEY}"
  DO_SPACES_REGION: "${DO_SPACES_REGION}"
  DO_SPACES_ENDPOINT: "${DO_SPACES_ENDPOINT}"
  DO_SPACES_BUCKET: "${DO_SPACES_BUCKET}"

packages:
  - name: golf
    functions:
      - name: func1
        runtime: python:3.11
        main: main         # function inside __main__.py
        web: false
        environment:
          ENV: production
      - name: func2
        runtime: python:3.11
        main: main
        web: false
        environment:
          ENV: production
      - name: func3
        runtime: python:3.11
        main: main
        web: false
        environment:
          ENV: production
  1. Set up each .include file like this:
__main__.py
requirements.txt
../../../lib/common
../../../lib
  1. Deployed the project doctl serverless deploy . --remote-build

I did see the functions deployed, but when I invoked them, they got an error saying that the modules (listed in requirements.txt) could not be found.

I also tried to add a build.sh with the following basic script:

#!/bin/bash
pip install -r requirements.txt -t .

This did not do anything. And I tried other variations-- all of which did not work. NOTE: I did make this executable chmod +x packages/samples/*/build.sh

I’m looking for help on adding these libraries to serverless functions. I’m new to Digital Ocean, but the documentation is lacking on how you specifically should add packages to serverless functions that aren’t in the primary runtime environment (Python 3.11). If there is no clear solution, I will have to either containerize an application or set it up on a droplet. These latter alternatives I was looking to avoid since this is a very basic job and doesn’t require that much compute.

Appreciate your help.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.