Forums

simplejson import error while runing bottle app

When i import simplejson in python CLI it is working fine but,when invoking it through bottle web app facing this error "ImportError: No module named 'simplejson'"

i tried "pip install --user simplejson".system says it already exists in python libraries.

code snippet i am using :

import urllib
import simplejson

googleGeocodeUrl = 'http://maps.googleapis.com/maps/api/geocode/json?'

def get_coordinates(query, from_sensor=False):
    query = query.encode('utf-8')
    params = {
        'address': query,
        'sensor': "true" if from_sensor else "false"
    }
    url = googleGeocodeUrl + urllib.urlencode(params)
    json_response = urllib.urlopen(url)
    response = simplejson.loads(json_response.read())
    if response['results']:
        location = response['results'][0]['geometry']['location']
        latitude, longitude = location['lat'], location['lng']
        print query, latitude, longitude
    else:
        latitude, longitude = None, None
        print query, "<no results>"
    return latitude, longitude

That's a bit strange. It's possible that your path is incorrect, or perhaps the version of Python you're pip installing to is different to the one in your web app. Anyway, that's moot since Python has JSON build in since 2.6 - here are the docs