No module named error when importing installed libraries

Trying to deploy a python script as Function, this script has dependencies. Using the sample code (, I can deploy my script as long as I don’t import any of the dependencies.

If I try to import library that was successfully installed I get this error 2022-10-05T19:04:10.385463002Z stderr: Invalid action: No module named 'pdfrw'

import os, json, sys
import pdfrw
from datetime import date

def main(args):
      name = args.get("name", "stranger")
      greeting = "Hello  " + name + "!"
      return {"body": os.getcwd() + ':' + os.environ['PATH']}

set -e
virtualenv venv
source venv/bin/activate
python3 -m pip install -r requirements.txt



Result from

created virtual environment in 3727ms"
 creator CPython3Posix(dest=/tmp/slices/builds/fn-0c691d34-dc60-4292-a56b-be4aa0adddbe/sample_hello..."
 seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data..."
 added seed packages: pip==21.1.2, setuptools==57.0.0, wheel==0.36.2"
 activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshAc..."
Collecting pdfrw"
 Downloading pdfrw-0.4-py2.py3-none-any.whl (69 kB)"
Installing collected packages: pdfrw"
Successfully installed pdfrw-0.4"
WARNING: You are using pip version 21.1.2; however, version 22.2.2 is available."
"You should consider upgrading via the '/tmp/slices/builds/fn-0c691d34-dc60-4292-a56b-be4aa0adddbe/sa..."

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Pinned Answer

I found the problem. I had to use virtualenv as the name instead of venv

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.