PyCharm - Can't create App Engine Application

2019-01-29 01:52发布

问题:

The last few days I tried to create an App Engine Application based on DJango using PyCharm Professional 2016.3.2..

But everytime I try to create a new App Engine Application using Django as an third-party library PyCharm throws an Error and tells 'Create App Engine Application - Incorrect or corrupted App Engine SKD: cannot finde DJango installation'.

I already tried to install everything again, including Python, PyCharm, Django and the SDK, but it still doesn't work.

I would really appreciate any kind of help, because this problem drives me crazy.

回答1:

You need to install extras.

gcloud components install app-engine-python-extras

And then try to create django (app engine) project again.



回答2:

The legacy Appengine SDK ships with some Django versions included in its lib folder.

$  find 1.9.40/ -type d -name [Dd]jango*
1.9.40/google_appengine/lib/jinja2-2.6/examples/rwbench/django
1.9.40/google_appengine/lib/jinja2-2.6/ext/django2jinja
1.9.40/google_appengine/lib/django-1.4
1.9.40/google_appengine/lib/django-1.4/django
1.9.40/google_appengine/lib/PyAMF-0.6.1/pyamf/tests/adapters/django_app
1.9.40/google_appengine/lib/django-1.2
1.9.40/google_appengine/lib/django-1.2/django
1.9.40/google_appengine/lib/PyAMF-0.7.2/pyamf/adapters/tests/django_app
1.9.40/google_appengine/lib/django-0.96
1.9.40/google_appengine/lib/django-0.96/django
1.9.40/google_appengine/lib/django-1.5
1.9.40/google_appengine/lib/django-1.5/django
1.9.40/google_appengine/lib/django-1.3
1.9.40/google_appengine/lib/django-1.3/django
1.9.40/google_appengine/lib/django-1.9
1.9.40/google_appengine/lib/django-1.9/django
1.9.40/google_appengine/google/appengine/_internal/django
1.9.40/google_appengine/google/appengine/ext/django
1.9.40/google_appengine/google/appengine/ext/builtins/django_wsgi
1.9.40/google_appengine/google/storage/speckle/python/django

However the Google Cloud SDK does not include any Django versions in lib, only with Django utilities for its own internal use.

$  gcloud --version
Google Cloud SDK 138.0.0
app-engine-python 1.9.49
...

$  find google-cloud-sdk/ -type d -name [Dd]jango*
google-cloud-sdk/lib/third_party/oauth2client/contrib/django_util
google-cloud-sdk/lib/googlecloudsdk/third_party/appengine/ext/builtins/django_wsgi
google-cloud-sdk/platform/google_appengine/lib/jinja2-2.6/examples/rwbench/django
google-cloud-sdk/platform/google_appengine/lib/jinja2-2.6/ext/django2jinja
google-cloud-sdk/platform/google_appengine/lib/PyAMF-0.6.1/pyamf/tests/adapters/django_app
google-cloud-sdk/platform/google_appengine/lib/PyAMF-0.7.2/pyamf/adapters/tests/django_app
google-cloud-sdk/platform/google_appengine/google/appengine/_internal/django
google-cloud-sdk/platform/google_appengine/google/appengine/ext/django
google-cloud-sdk/platform/google_appengine/google/appengine/ext/builtins/django_wsgi
google-cloud-sdk/platform/google_appengine/google/storage/speckle/python/django
google-cloud-sdk/platform/gsutil/third_party/oauth2client/oauth2client/contrib/django_util
google-cloud-sdk/.install/.backup/lib/googlecloudsdk/third_party/appengine/ext/builtins/django_wsgi
google-cloud-sdk/.install/.backup/platform/google_appengine/lib/jinja2-2.6/examples/rwbench/django
google-cloud-sdk/.install/.backup/platform/google_appengine/lib/jinja2-2.6/ext/django2jinja
google-cloud-sdk/.install/.backup/platform/google_appengine/lib/PyAMF-0.6.1/pyamf/tests/adapters/django_app
google-cloud-sdk/.install/.backup/platform/google_appengine/lib/PyAMF-0.7.2/pyamf/adapters/tests/django_app
google-cloud-sdk/.install/.backup/platform/google_appengine/google/appengine/_internal/django
google-cloud-sdk/.install/.backup/platform/google_appengine/google/appengine/ext/django
google-cloud-sdk/.install/.backup/platform/google_appengine/google/appengine/ext/builtins/django_wsgi
google-cloud-sdk/.install/.backup/platform/google_appengine/google/storage/speckle/python/django
google-cloud-sdk/.install/.backup/platform/gsutil/third_party/oauth2client/oauth2client/contrib/django_util

The solution is to install Django according to Google's instructions for installing third party packages, that is:

  1. Install django in your third party libs folder:pip install django -t lib
  2. Add from google.appengine.ext import vendor;vendor.add('lib') in your appengine_config.py module


回答3:

As @snakecharmerb observed the django packages are missing in the app-engine-python component (1.9.49) of the cloud SDK (138.0.0).

They are, however, present in the standalone GAE SDK (also 1.9.49):

/usr/local # diff google_appengine_1.9.49/lib google-cloud-sdk-138.0.0/platform/google_appengine/lib | grep -vi common
Only in google_appengine_1.9.49/lib: django-0.96
Only in google_appengine_1.9.49/lib: django-1.2
Only in google_appengine_1.9.49/lib: django-1.3
Only in google_appengine_1.9.49/lib: django-1.4
Only in google_appengine_1.9.49/lib: django-1.5
Only in google_appengine_1.9.49/lib: django-1.9
Only in google_appengine_1.9.49/lib: graphy

So an alternative to vendoring django into your app might be to switch to this SDK instead of the cloud SDK. See What is the relationship between Google's App Engine SDK and Cloud SDK?, including comments.

Note that it's not the recommended way these days, tho.

You could also install both and try to copy/symlink the missing packages into the cloud SDK. YMMV.

To download the GAE SDK in the Download the SDK for App Engine page click on the Optionally, you can also download the original App Engine SDK for Python. "link" - it's actually a control for the expandable download section below: