Wonderhost
Wonderhost

Reputation: 144

python json module import error

I am getting the following error while using python json module

# python
Python 2.4.3 (#1, Jan 11 2013, 02:09:42) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named json
>>> 

can somebody help me on this?

Upvotes: 1

Views: 29621

Answers (5)

mvarge
mvarge

Reputation: 324

To not worry about your Python version and (simple) portability:

try:
    import json
except ImportError:
    import simplejson as json

Upvotes: 4

Techiescorner
Techiescorner

Reputation: 811

use simplejson it will work

# python
Python 2.4.3 (#1, Jan 11 2013, 02:09:42) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import simplejson
>>> 

Upvotes: 5

Chitrank Dixit
Chitrank Dixit

Reputation: 4051

please use the stable python 2.7.x that would solve your issue and after that try using json

>>> import json

also you can use dir() command to check the methods and classes that comes with the json module in python programming, using the dir()

>>> dir(json)
['JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_default_decoder', '_default_encoder', 'decoder', 'dump', 'dumps', 'encoder', 'load', 'loads', 'scanner']

Upvotes: 0

ode2k
ode2k

Reputation: 2723

as idjaw commented above.

You need to use:

import json

(Not jason)


Also, you need to use Python 2.6 or greater.

Upvotes: 1

Deusdeorum
Deusdeorum

Reputation: 1426

You are using Python 2.4.3 and json seems to be new in python 2.6, please update python.

Upvotes: 1

Related Questions