0

I am creating a Python Web App in Google App engine. When I

sudo pip install

a third party library and then try to import it, I get the error 'ImportError: No module named x'. Where x is the name of that library. In my case as an example: Boto, Boto3, Fask etc.

If I go into shell in GAE and type python >> import X the library can be used inside the python environment. When deploying the app though or running the app in the virtaul server in Google App Engine I get the module import error.

  • I even tried methods like: python >> import sys >> sys.path.insert(0, "path_here")
  • export PYTHONPATH and selected where those libraries are located

I even followed several Q&A here in Stackoverflow without any success, can somebody please give me a proper way to fix the import error in Google App Engine?

FYI

  • I am not using any local environment in my pc, I am working directly through the GAE bash console, the launch code editor in GAE and I am running the command dev_appserver.py $PWD
  • When I do

pip freeze

I can see that the modules are currently installed and deployed on the GAE virtual environment. Is there a problem with my path? What's the best approach to make GAE load my already installed third party libraries.

UPDATE: Importing the library directly on the python shell from Google App Engine works just fine. Importing the library on my python app index.py file results in the error. Python import directly from Shell Python import to the index.py file

papouyis
  • 1
  • 4
  • Are you using GAE standard og GAE flexible environment? – Arne S Jun 10 '17 at 20:35
  • Hello, thank you for your question. Where can I determine if it is a standard or a flexible environment? – papouyis Jun 10 '17 at 20:40
  • That is a selection you do when you create the app. Eg have a look in https://console.cloud.google.com/appengine/versions?project=[your project id] . Reason for asking is that handling of external libraies are different. For GAE standard use of external libraries are limited. What library are you trying to include? – Arne S Jun 10 '17 at 20:49
  • I am trying to import boto, boto3 and some other third party libraries for the deployment of charts. At the moment it is a standard environment. – papouyis Jun 10 '17 at 20:51
  • 1
    Possible duplicate of [How to include third party Python libraries in Google App Engine?](https://stackoverflow.com/questions/14850853/how-to-include-third-party-python-libraries-in-google-app-engine) – Arne S Jun 10 '17 at 21:01
  • If you check above the 'UPDATE' section I included two images. I already did what it is said in that post with no luck. How can I move from a standard environment to a flexible one without starting a new project from scratch? – papouyis Jun 10 '17 at 21:10
  • https://cloud.google.com/appengine/docs/flexible/python/migrating – Arne S Jun 10 '17 at 21:20
  • not much of help. Do you have direct instructions like step by step? Because what it is written on that particular page doesn't seem to help much. – papouyis Jun 10 '17 at 21:26

1 Answers1

0

Though this is an old thread, adding this answer now:

Run command : gcloud components list

This will show the different components installed and not in your environment.

Install app-engine-python components if not installed:

gcloud components install app-engine-python

gcloud components install app-engine-python-extras

If it doesn't work:

In Windows, uninstall and download and install Google-sdk (check the python version you need). Delete all the files the installer ask you to delete in the last step and run the gcloud component commands again.

Community
  • 1
  • 1