pythonpython-3.xsimplejson

Simplejson error Python 3.3


I'm trying to run a program that imports simplejson. When I run it in Python 2.7 it's ok, but when I run it in Python 3.3 it says:

File "C:\Python33\lib\simplejson__init__.py", line 111, in <module>
from decoder import JSONDecoder, JSONDecodeError
ImportError: No module named 'decoder'


Solution

  • There is no need to use the external simplejson library. The json module included in the Python 3 standard library is the exact same module, but maintained as part of the Python distribution. Quoting from the simplejson PyPI page:

    simplejson is the externally maintained development version of the json library included with Python 2.6 and Python 3.0, but maintains backwards compatibility with Python 2.5.

    Use the following code to switch to simplejson if json isn't present (only for Python 2.5, the library is included in 2.6 and up):

    try:
        import json
    except ImportError:
        # python 2.5
        import simplejson as json