0
votes

Just updated GAE Python dev environment from 1.7.0 to 1.7.7, and hit an error:

ImportError: No module named json

So I created a minimum test case, here's the app.yap:

application: myapp

version: 1
api_version: 1
runtime: python27
threadsafe: true  

libraries:
- name: jinja2
  version: "2.6"

handlers:
- url: /test.*
  script: test.app
  login: required

- url: /.*
  script: routes.app
  login: required

and the test.py:

import webapp2
import json

class MainHandler(webapp2.RequestHandler):

    def get(self):
        self.response.out.write("test.py")

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

Switching dev environments is perfectly consistent - the error is thrown on 1.7.7 but not 1.7.0 (running dev environment from terminal on Linux). I've not tried uploading this to a production environment. It occurred while attempting to upgrade from Python 2.5 to 2.7, so may be due to my unfamiliarity with 2.7.

2
are you running the python 2.7 interpreter and runtime? sounds like your python install might be missing the json library.dragonx
Yep, python -V gives Python 2.7.3. Also, it runs fine when I downgrade the dev environment to 1.7.0 from the latest (1.7.7).cbootle
Can you import json in the python interpreter?MichaelJCox
Yes. Have found my noobie error, see below.cbootle

2 Answers

2
votes

It was a noobie mistake. As mentioned, I was upgrading from 2.5 to 2.7, during which I moved from importing simplejson to json.

During 2.5 development, I had created a file called json.py, which of course caused a conflict when upgrading to 2.7 and trying to import json, so I renamed that file. Sorry guys, I should have mentioned that, but if I had done so, I would have realized... the json.pyc was still hanging around!

Removing the json.pyc file fixed it. However, it doesn't explain why the presence of json.pyc affected 1.7.7 but not 1.7.0 - switching between the two was perfectly repeatable.

0
votes

You can check for simplejson, as in this post, except I think in GAE you get simplejson from django.utils:

try: from django.utils import simplejson as json
except ImportError: import json

But the Python 2.7 runtime should allow for import json. If the above worked, you were probably running on 2.5.