Search code examples
pythongoogle-app-enginepycharm

Python module resolution for Google App Engine vs Google Cloud NDB


I'm trying to create a Python 3 application for Google App Engine (using PyCharm).

I think I'm running into a basic problem in which a module named "google" is defined in 2 places: in the Google App Engine directory created by gcloud install, and in my project's venv directory when I pip install add-ons such as google-cloud-ndb via the requirements.txt file.

When I select PyCharm Settings | Frameworks | App Engine and specify the directory into which gcloud installed App Engine, the editor can resolve things like import google.appengine but not import google.cloud. If I unselect the App Engine Framework, then the editor can find import google.cloud, but not import google.appengine.

All the code examples just list import google.xyz, so I imagine when I deploy, Google will resolve all this correctly. But it also means I probably shouldn't play around with naming or imports either.

This is so basic. How is this handled?


Solution

  • The solution is to create a Flask project, not an App Engine project, and then copy installed App Engine modules into the project's venv, so PyCharm can see all google sub-modules in one place.

    There's more to getting PyCharm to truly develop/run/debug Python 3 App Engine apps, though: see How to test/run/debug Non-Legacy App Engine project using PyCharm on Windows