1

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?

1
  • 2
    you should upgrade your python 2.4 is quite old unless you need to maintain old stuff ? Commented Mar 11, 2016 at 14:37

5 Answers 5

5

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
>>> 
Sign up to request clarification or add additional context in comments.

Comments

4

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

try:
    import json
except ImportError:
    import simplejson as json

1 Comment

Can you explain what the above statements are doing as I am new to python
1

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

Comments

1

as idjaw commented above.

You need to use:

import json

(Not jason)


Also, you need to use Python 2.6 or greater.

2 Comments

import json will not give you that error, as it is a valid module.
@ode2k it will if he is using an old python
0

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']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.