问题
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:
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
>>>
回答2:
To not worry about your Python version and (simple) portability:
try:
import json
except ImportError:
import simplejson as json
回答3:
You are using Python 2.4.3 and json seems to be new in python 2.6, please update python.
回答4:
as idjaw commented above.
You need to use:
import json
(Not jason)
Also, you need to use Python 2.6 or greater.
回答5:
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']
来源:https://stackoverflow.com/questions/35942561/python-json-module-import-error