GoogleCloudPlatform / functions-framework-python

FaaS (Function as a service) framework for writing portable Python functions
https://pypi.org/p/functions-framework/
Apache License 2.0
878 stars 118 forks source link

Provided code location is not a loadable module. Did you specify the correct location for the module defining your function? #346

Open dvmorris opened 2 months ago

dvmorris commented 2 months ago

Attempting to follow the python tutorial in README.md in a Google Cloud Shell environment, and I get the following error:

`

Steps to reproduce

main.py

import flask
import functions_framework

@functions_framework.http
def hello(request: flask.Request) -> flask.typing.ResponseReturnValue:
    return "Hello world!"

requirements.txt

functions-framework
flask

cmd

$ pip3 install -r requirements.txt 
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: functions-framework in /home/admin_/.local/lib/python3.10/site-packages (from -r requirements.txt (line 1)) (3.8.1)
Requirement already satisfied: flask in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 2)) (3.0.3)
Requirement already satisfied: click<9.0,>=7.0 in /usr/local/lib/python3.10/dist-packages (from functions-framework->-r requirements.txt (line 1)) (8.1.7)
Requirement already satisfied: cloudevents<2.0.0,>=1.2.0 in /home/admin_/.local/lib/python3.10/site-packages (from functions-framework->-r requirements.txt (line 1)) (1.11.0)
Requirement already satisfied: Werkzeug<4.0.0,>=0.14 in /usr/local/lib/python3.10/dist-packages (from functions-framework->-r requirements.txt (line 1)) (3.0.3)
Requirement already satisfied: watchdog>=1.0.0 in /home/admin_/.local/lib/python3.10/site-packages (from functions-framework->-r requirements.txt (line 1)) (5.0.3)
Requirement already satisfied: gunicorn>=22.0.0 in /home/admin_/.local/lib/python3.10/site-packages (from functions-framework->-r requirements.txt (line 1)) (23.0.0)
Requirement already satisfied: Jinja2>=3.1.2 in /usr/local/lib/python3.10/dist-packages (from flask->-r requirements.txt (line 2)) (3.1.4)
Requirement already satisfied: itsdangerous>=2.1.2 in /usr/local/lib/python3.10/dist-packages (from flask->-r requirements.txt (line 2)) (2.2.0)
Requirement already satisfied: blinker>=1.6.2 in /usr/local/lib/python3.10/dist-packages (from flask->-r requirements.txt (line 2)) (1.8.2)
Requirement already satisfied: deprecation<3.0,>=2.0 in /home/admin_/.local/lib/python3.10/site-packages (from cloudevents<2.0.0,>=1.2.0->functions-framework->-r requirements.txt (line 1)) (2.1.0)
Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gunicorn>=22.0.0->functions-framework->-r requirements.txt (line 1)) (24.1)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from Jinja2>=3.1.2->flask->-r requirements.txt (line 2)) (2.1.5)

$ functions-framework --target hello
Provided code location '/home/admin_/functions-framework-test' is not a loadable module.
Did you specify the correct location for the module defining your function?
Could not load the function, shutting down.
dvmorris commented 2 months ago

This process works fine on my MacOS laptop, so I must be just misunderstanding something about my Cloud Shell environment.