Reputation: 3935
I wanted to add a google.cloud.storage dependency to my project so I tried to install this dependency with
pip install --upgrade google-cloud-storage
Running my app again with dev_appserver, it shows me that my gcloud components needed to be updated. Ok so, gcloud components update
And in my src/__init__.py
file, I got the code that tells gcloud in which folder to look for dependencies like this:
from google.appengine.ext import vendor
vendor.add('src/libs')
All the dependencies are installed correctly, except that I'm getting the error ImportError: No module named google.oauth2
PS: My app is using OAuth2 to secure access to the API. And it was working correctly before I do a components update, now even if I rollback code, remove the libs folder and install again dependencies, I still got the No module error, and it seems like dev_appserver is not looking for that dependency inside the libs folder !
Here's the result of gcloud --version
:
Google Cloud SDK 188.0.1
app-engine-python 1.9.66
app-engine-python-extras 1.9.63
bq 2.0.28
core 2018.02.08
gsutil 4.28
And here's the Traceback:
Traceback (most recent call last):
File "/home/login/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/login/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/home/login/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
__import__(cumulative_path)
File "/home/headless/Documents/Projects/meterFleet/app-backend/src/main.py", line 5, in <module>
from src.app.user.api import UserApi
File "/home/headless/Documents/Projects/meterFleet/app-backend/src/app/user/api.py", line 7, in <module>
from src.googleapis.iam import getIamPolicy, addIapUser, deleteIapUser
File "/home/headless/Documents/Projects/meterFleet/app-backend/src/googleapis/iam.py", line 5, in <module>
from src.common.authentication import OAuth
File "/home/headless/Documents/Projects/meterFleet/app-backend/src/common/authentication.py", line 3, in <module>
from google.oauth2 import service_account
File "/home/login/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/runtime/sandbox.py", line 1147, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named google.oauth2
Upvotes: 18
Views: 40695
Reputation: 1922
In my case it was because the file itself was called google.py
, so it was trying to import itself.
Upvotes: 3
Reputation: 11
I had virtualenv created and was trying to run a script where you insert data into google cloud bigquery with a service account and automate it using cron file , the solution for me was to replace usr/local/bin/python to my virtualenv python path.
old cron file :
30 11 * * * /usr/local/bin/python3 /opt/deployment/cronJobs/ProjectAssetMetrics/daily/updateCCMSCountJob.py > /opt/deployment/cronJobs/ProjectAssetMetrics/daily/updateCCMSCountJob.log 2>&1 in your
new cron file :
16 12 * * * /opt/.envs/sl_dw/bin/python3 /opt/deployment/cronJobs/ProjectAssetMetrics/daily/updateCCMSCountJob.py > /opt/deployment/cronJobs/ProjectAssetMetrics/daily/updateCCMSCountJob.log 2>&
You can check your python path by typing:
$ which python
make sure you activate your virtualenv if any
Upvotes: 1
Reputation: 5903
I decided to use pipenv to solve this issue.
pip3 install pipenv
pipenv install
pipenv shell
Then install the libraries you need.
Upvotes: 1
Reputation: 356
In case none of the above works for you - I found this answer from GitHub by hiranya911. It solved my problem perfectly.
Upvotes: 0
Reputation: 2372
Just upgrading some python packages solved my issue:
pip install --upgrade google-auth google-auth-httplib2 google-api-python-client
Upvotes: 7
Reputation: 3935
EDIT: I think you never get this error if you use something like virtualenv.
The problem was coming from the dependencies being installed in both the project folder (in the src/libs
folder), and in the python local libs folder (/usr/local/python2.7/dist-packages). I removed the google libraries from the python libs folder and it's now working again !
Upvotes: 4
Reputation: 1327
I've had this issue quite a bit. I uninstalled all Google packages from my local machine, deleted the lib folder in my GAE app folder, created it again then executed:
pip install -t lib google-auth google-auth-httplib2 google-api-python-client --upgrade
That should fix your problem.
Upvotes: 14