Report this

What is the reason for this report?

Why is my requirements.txt not being used?

Posted on September 2, 2025

I’m trying to deploy a Python function to Functions that requires packages to be imported.

The following is the tree of my directory

ingest-attempt2
    │   .gitignore
    │   project.yml
    │
    ├───.deployed
    │       versions.json
    │
    └───packages
        └───sample
            └───hello
                    requirements.txt
                    __deployer__.zip
                    __main__.py

This is my requirements.txt

numpy

…and this is my project.yml

parameters: {}
environment: {}
packages:
    - name: sample
      shared: false
      environment: {}
      parameters: {}
      annotations: {}
      functions:
        - name: hello
          binary: false
          main: "main"
          runtime: python:default
          web: true
          webSecure: false
          parameters: {}
          environment: {}
          annotations: {}
          limits: {}

When I run the function in DigitalOcean, I get the following error

2025-09-02T20:09:16.864955434Z stderr: Invalid function: No module named 'numpy'

I can see that someone has asked a similar question here but I don’t think I have made a mistake with my folder names as this person has.

Please could someone enlighten me?



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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey!

If I remember this correctly the DigitalOcean Functions platform doesn’t automatically install from requirements.txt. You also need a build.sh script in the same folder as your __main__.py and requirements.txt.

For example, inside packages/sample/hello/ you’d have:

__main__.py
requirements.txt
build.sh

Your requirements.txt:

package-name==1.2.3...

Your build.sh:

#!/bin/bash
set -e

virtualenv --without-pip virtualenv
# For Python 3.11 runtime
pip install -r requirements.txt --target virtualenv/lib/python3.11/site-packages

Then deploy with:

doctl serverless deploy .

This way the build system creates a virtualenv and installs your deps so they’re available to your function.

Docs: Python runtimes with external packages

Heya, @donught

Python functions with external dependencies not provided by the runtime can be deployed with a build script and a requirements.txt file.

First make sure that the file containing the handler function is named __main__.py.

Regards

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.