0

I'm attempting to use the command dev_appserver.py ./ from my application directory, but it's throwing the following error.

ERROR    2016-01-04 04:47:51,421 wsgi.py:263] 
Traceback (most recent call last):
  File "/Users/Joshua/Scripts/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Users/Joshua/Scripts/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Users/Joshua/Scripts/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/Users/Joshua/Projects/inkren/skritter-api/main.py", line 2, in <module>
    from gcloud import datastore
ImportError: No module named gcloud

I'm running a virtualenv that has gcloud installed and also have the gcloud sdk installed with the proper python component. The gcloud library is found when I run python ./main.py.

# main.py

import webapp2
from gcloud import datastore


class MainPage(webapp2.RequestHandler):
    def get(self):
        client = datastore.Client(dataset_id='my-project')
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, World!')

app = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)

What I'd like to do is be able to run my code locally in the browser. Is there a way to get dev_appserver.py to recognize the gcloud library?

Joshua
  • 1,260
  • 3
  • 17
  • 33
  • Hello again. That's strange. Can you open a python shell and try to type in: `from gcloud import datastore` to see if it throws an error? – Mmm Donuts Jan 04 '16 at 05:25
  • Remeber appengine runs in an emulated sandbox, the libraries have to be available in the project and not just in virtualenv. See docs on including thirdparty libraries, As an aside why on earth would you try to use datastore Client in appengine ? – Tim Hoffman Jan 04 '16 at 09:42
  • @Kris Howdy, as you might have guessed running that from my python console returns with no error. – Joshua Jan 04 '16 at 14:53
  • @TimHoffman I'm trying to make api endpoints that read from our datastore. I want to be able to test things locally using live data without have to deploy. – Joshua Jan 04 '16 at 14:55

2 Answers2

1

Is using the python development server from gcloud still a problem? I'm successfully using dev_appserver.py from the terminal. See reference.

Perhaps the install and setup instructions have improved since a year ago. I believe the installation puts the file, dev_appserver.py, in your system path, even on Windows, so it is accessible from the terminal.

cyrf
  • 5,127
  • 6
  • 25
  • 42
0

I did a bit of research on this, so... Okay, here's what you've got to do.

takes a breath

Head over to this gentleman's GitHub page, and download the package as a zip. https://github.com/dhermes/test-gcloud-on-gae

Now, you need to add some folders/files from his folder into yours to get gcloud working.

1) Open the application folder and put the vendor folder into your root directory. This folder contains the gcloud package, as well as many others. You can delete the others if you want.

2) Add the appengine_config.py into your root directory as well. This file tells app engine where your third party packages are.

3) Add darth.py to your root directory as well. This is just a help file.

Actually, that should do it. This gentleman wrote some scripts for using third party apps with app engine, and they're quite useful. Let me know if your import works after doing that!

I tested it locally and it works perfectly. Basically, any third party python packages work with app engine, as long as there are no other languages within them such as C.

Mmm Donuts
  • 9,551
  • 6
  • 27
  • 49
  • Wowzers, that's quite a hack to do something that one would thing should be fairly standard practice. I did try messing with third party stuff using `appengine_config.py` to no avail, but will have it give this a go later. – Joshua Jan 04 '16 at 14:51
  • @Josh yeah, I know... it's not as much as you think. A download and 3 copy/pastes and you're done. It's simply because of what TimHoffman said. App Engine runs in a sandbox, however it will run anything that only contains python code (I mean, think about it... they're just python files). – Mmm Donuts Jan 04 '16 at 16:21
  • I did get it recognize gcloud using the dev server, but hacking vendor libraries isn't something I really want to deal with. It becomes especially tedious when dealing with updates. The version used in that example is 0.3.3 and the current stable is 0.8.0, which is so old it's not even listed on their documentation version list. – Joshua Jan 06 '16 at 22:06