Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions-framework does not use the sourced venv #219

Open
saumac opened this issue Feb 16, 2023 · 2 comments
Open

functions-framework does not use the sourced venv #219

saumac opened this issue Feb 16, 2023 · 2 comments
Labels
bug Something isn't working P3

Comments

@saumac
Copy link

saumac commented Feb 16, 2023

I am using the functions-framework to develop on my local machine and I have created a python venv for the project. Following is a description of my issue:

  • I have installed the firebase_admin lib within the venv and I am importing it within the src code.
  • I am running the command: functions-framework --source ./src/main.py --target main
  • The above command fails with following error: ModuleNotFoundError: No module named 'firebase_admin'
  • The above error does not occur if I install the firebase_admin lib outside the venv (global scopte)

Is there a way to specify which python env to use or is always set to the global python scope?

@josephlewis42 josephlewis42 added bug Something isn't working P3 labels Apr 24, 2023
@garethgeorge
Copy link
Contributor

Hi, sorry you're running into a bit of trouble here. The python functions framework uses pip and your requirements.txt only to manage dependencies (make sure that every package your function depends on is listed in the requirements.txt). See specifying python dependencies for more details on the specifics.

Many users use a venv for local development and add the venv folder to their .gcloudignore to avoid uploading it (and to allow pip to manage dependencies as specified in their requirements.txt) on deploy.

It may be worth converting this to a feature request if there are workflows that you're using with your virtualenv that aren't well supported when using pip on deploy.

@bramp
Copy link

bramp commented Mar 13, 2024

I'm not sure if its related, but I was having a similar problem:

# Setup virtual env
$ python3.12 -m venv .venv
$ source .venv/bin/activate

# Install everything in virtual env
$ pip install -r requirements.txt

# Now run
$ functions-framework
...
ModuleNotFoundError: No module named 'google.cloud.logging'

google.cloud.logging is in my requirements.txt, but when I run which functions-framework I was getting /opt/homebrew/bin/functions-framework, not the expected .venv/bin/functions-framework. This explains why it couldn't find the installed dependencies.

On my mac, running rehash fixed this:

$ which functions-framework
/opt/homebrew/bin/functions-framework

$ rehash

$ which functions-framework
..../.venv/bin/functions-framework

now everything works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P3
Projects
None yet
Development

No branches or pull requests

4 participants