getting-started-python: ImportError: No module named appengine.api (even after app-engine-python installation)

Hi,

I used a newly created CentOS7 VM in Google Cloud Platform to try to run the following Python code (Python version: 2.7.5):-

from google.appengine.api import urlfetch

But I got this error message:-

ImportError: No module named appengine.api

Previously, I already have already installed app-engine-python and app-engine-python-extras in gcloud. For example, if I now run this:-

yum install google-cloud-sdk-app-engine-python

I would get this to tell me that it is already installed:-

Package google-cloud-sdk-app-engine-python-194.0.0-1.noarch already installed and latest version Nothing to do

And if I now run this:-

gcloud components list

Again, I would get this to tell me that the app-engine components are already installed:-

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┐
│                                                   Components                                                   
│
├──────────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────
┤
│      Status      │                         Name                         │            ID            │    Size   
│
├──────────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────
(...............................................................................)
(skipped showing other gcloud components)
(...............................................................................)
│ Installed        │ gcloud app Python Extensions                         │ app-engine-python        │   6.2 MiB 
│
│ Installed        │ gcloud app Python Extensions (Extra Libraries)       │ app-engine-python-extras │  27.8 MiB 
│
└──────────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────

I tried to download pip and use pip to install the stuff again, and I if I run pip freeze | grep ^google I would get this (without showing app-engine ?):-

google-api-core==0.1.4
google-auth==1.4.1
google-cloud-bigquery==0.28.0
google-cloud-bigquery-datatransfer==0.1.1
google-cloud-container==0.1.1
google-cloud-core==0.28.1
google-cloud-datastore==1.4.0
google-cloud-dns==0.28.0
google-cloud-firestore==0.28.0
google-cloud-language==1.0.1
google-cloud-monitoring==0.28.1
google-cloud-speech==0.30.0
google-cloud-trace==0.17.0
google-cloud-translate==1.3.1
google-cloud-vision==0.29.0
google-compute-engine==2.7.6
google-gax==0.15.16
google-resumable-media==0.3.1
googleapis-common-protos==1.5.3

How can I get it solved? I just want to run from google.appengine.api import urlfetch successfully.

Thanks in advance!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 28 (1 by maintainers)

Most upvoted comments

Try to use miniconda conda.io/miniconda

On Thu, Sep 27, 2018, 9:57 PM Evan Fir notifications@github.com wrote:

You need to add the following to your ~/.bash_profile file

export GOOGLE_APP_ENGINE_DIR=/usr/local/google_appengine

I tried this and I’m still getting the same error. I don’t use virtual environment. MacOS Sierra 10.12.6 (16G1510) Python 3.7.0

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/GoogleCloudPlatform/getting-started-python/issues/157#issuecomment-425305389, or mute the thread https://github.com/notifications/unsubscribe-auth/ACYvDw2hVWlB_1YQQ0ZoISz01oGTVKggks5ufZAkgaJpZM4S7ocQ .

Hi everyone!

In most cases Cloud SDK or the package manager on your system installs packages app-engine-python and app-engine-python-extras inside Cloud SDK itself, i.e. if your Cloud SDK resides in /usr/lib64/google-cloud-sdk/, the packages will only be available in /usr/lib64/google-cloud-sdk/platform/google_appengine. Cloud SDK will NOT add this directory to your PYTHONPATH, thus Python will not search this location for said packages and will return the errors reported.

To fix this issue, simply add YOUR-CLOUD-SDK-INSTALLATION/platform/google_appengine to your PYTHONPATH. More specifically, run the command below:

export PYTHONPATH=${PYTHONPATH}:$(gcloud info --format="value(installation.sdk_root)")/platform/google_appengine

Additionally, note that Python will only search the first matched directory in the given paths without further instructions. For example, if you imported both google.mypackage and google.appengine.api in your script and these two packages live in two separate places, Python will report an error for either of them as it cannot find both in the same place. This should not be an issue for most Google Cloud Client Libraries, since their __init__.py is specified with __path__ = pkgutil.extend_path(__path__, __name__), which extends the path and tells Python to continue searching in the case of a mismatch. Should your error persists despite correct PYTHONPATH settings, check your site-packages folder and make sure that the __init__.py script under the google folder is corrected set.

michaelawyu

Same problem here. People have been reporting this on Stackoverflow for a long time now. We should not have to install these packages in the magic order to get them working. Especially since there are so many different official guides on install the Cloud SDK.

Same exact problem. A nightmare

Same problem here, i get error

No module named ‘google.appengine’

You need to add the following to your ~/.bash_profile file export GOOGLE_APP_ENGINE_DIR=/usr/local/google_appengine

Same problem, tried adding PATH mentioned above but none of them work. macOS Catalina python 3.7.4

I got it working on my Ubuntu VM. You need to add the following line to your bashrc file.

export PYTHONPATH="${PYTHONPATH}:/PATH_TO_GC_SDK/google-cloud-sdk/platform/google_appengine

Don’t forget to enter source ~/.bashrc afterwards.

You can verify whether the python interpreter can reference the package by importing sys, then printing sys.path. You should see the directory above listed in your path.

Same problem here export PYTHONPATH=“${PYTHONPATH}:/PATH_TO_GC_SDK/google-cloud-sdk/platform/google_appengine/google” does not work

Having the same error here, for me it seems the problem has to do with the fact that the site-packages folder already contains a folder named google, which was created when I installed google datastore package using pip. python 2.7.17