installing simplejson on the google appengine
Asked Answered
G

2

5

Super nub question time! I am trying to use simplejson on the google appengine. In a terminal on my machine I have simplejson installed and working. But my when I try to import it in a script running on the appengine I get an error saying no such library exists. If open the interactive console on my machine (from the link on http://localhost:8080/_ah/admin) and type "import simplejson" I get:

Traceback (most recent call last): File "/home/chris/google_appengine/google/appengine/ext/admin/init.py", line 210, in post exec(compiled_code, globals()) File "", line 1, in ImportError: No module named simplejson

Any thoughts?

Gwenette answered 26/4, 2010 at 7:2 Comment(1)
nevermind, here it is: from django.utils import simplejsonGwenette
H
14

Look in django package:

from django.utils import simplejson as json
obj = json.loads(json_string)

Since Sdk 1.4.2 Json can be imported with the following statement:

import simplejson

Note that on Python 2.7 runtime you can use the native Json library.

Herstein answered 26/4, 2010 at 9:0 Comment(3)
I've seen this answer given frequently to this question, but it seems a bit odd to me to import anything from the django package if the user is not using Django. Should non-Django users just add the generic simplejson directly to their project? Or is the version supplied by Google in the django package somehow better tuned to GAE then the generic version of simplejson? Since I use json so heavily I want to be sure that I am using the best version.Mm
Django is part of the SDK so i don't see problem to use it. You could also drop in simplejson in your project directory and use it directly. Remember that c speedup won't work, App Engine doesn't allow python extensions written in cHerstein
I haven't looked specifically at how Django packages simplejson, but importing only part of Django often leads to importing all of Django. I don't know whether this is the case here, but if so, you might be better off just using simplejson in your project directory.Critique
G
10

You no longer need to use the django package for simplejson on Google App Engine.

import simplejson as json

This is expecially handy for avoiding the flurry of warnings about django versions in your log file.

Genniegennifer answered 17/2, 2011 at 22:10 Comment(1)
Note that with python 2.7 you have to use json because simplejson is c-accelerated.Alphonsealphonsine

© 2022 - 2024 — McMap. All rights reserved.