Simplejson error Python 3.3

Question:

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:Python33libsimplejson__init__.py”, line 111, in <module>
from decoder import JSONDecoder, JSONDecodeError
ImportError: No module named ‘decoder’

Asked By: user3017348

||

Answers:

You need to install it properly. That means using easy_install simplejson or pip install simplejson. Since you are on windows neither of these command-line tools are installed by default.

However, there is also a half-automated way install a package properly: Download and unpack it to some temporary folder and then open a command line window inside the package’s folder and execute python setup.py install in there.

Extracting it manually to your Python folder is pretty much always a bad choice that is likely to mess up your python installation (in case any conflicts with existing files occur).

Answered By: ThiefMaster

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
Answered By: Martijn Pieters
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.