pythongoogle-app-enginegoogle-cloud-platformoauthflask-dance

ModuleNotFoundError: No module named 'flask_dance'" on Google Cloud run


I've built a flask app and deployed it on Google Cloud and am getting the following error when I build, and deploy:

ModuleNotFoundError: No module named 'flask_dance'"

I use the library as so:

from flask_dance.consumer import oauth_authorized
from flask_dance.contrib.google import make_google_blueprint, google

The app runs fine on localhost, and the build and deploy don't report any errors (it's just when I try to access the deployment via the given url that I get this error in GCP console.

My requirements.txt looks like:

blinker==1.4
CacheControl==0.12.6
cachetools==4.0.0
certifi==2019.11.28
cffi==1.14.0
chardet==3.0.4
Click==7.0
cryptography==2.8
firebase-admin==4.0.0
Flask==1.1.1
Flask-Dance==3.0.0
Flask-Login==0.5.0
Flask-WTF==0.14.3
google-api-core==1.16.0
google-api-python-client==1.7.11
google-auth==1.11.2
google-auth-httplib2==0.0.3
google-cloud-core==1.3.0
google-cloud-firestore==1.6.2
google-cloud-storage==1.26.0
google-resumable-media==0.5.0
googleapis-common-protos==1.51.0
grpcio==1.27.2
httplib2==0.17.0
idna==2.9
itsdangerous==1.1.0
Jinja2==2.11.1
MarkupSafe==1.1.1
msgpack==1.0.0
oauthlib==3.1.0
protobuf==3.11.3
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
pyOpenSSL==19.1.0
pytz==2019.3
requests==2.23.0
requests-oauthlib==1.3.0
rsa==4.0
six==1.14.0
spoonacular==3.0
uritemplate==3.0.1
urllib3==1.25.8
URLObject==2.4.3
Werkzeug==1.0.0
WTForms==2.2.1

and flask_dance appears there (and again, runs fine locally).

I don't know why I'm getting the module import error. Any help figuring out the root cause would be greatly appreciated.


Solution

  • Make sure you specify installing that module in Dockerfile:

    E.g.

    # Install production dependencies.
    RUN pip install Flask-Dance
    

    Or

    # Install production dependencies.
    RUN pip install -r requirements.txt
    

    See containerizing the app.