simplejson for Python on Mac OS X

04Apr10

Ran into an interesting problem with Python on Mac OS X (Snow Leopard). Part and parcel of writing web application is dealing with information transfer between the server and the client, and the most common format for this is JSON.

JSON is exceedingly common across the web, so imagine my surprise when I found that the default installation of Python on Mac OS X didn’t seem to include simplejson.

Resolving this is easy. The Python installation comes with a handy utility called easy_install, which, well, easily installs missing components:

$ sudo easy_install simplejson
Password:
Searching for simplejson
Reading http://pypi.python.org/simple/simplejson/
Reading http://undefined.org/python/#simplejson
Best match: simplejson 2.1.1
Downloading http://pypi.python.org/packages/source/s/simplejson/simplejson-2.1.1.tar.gz#md5=0bbe3a2e5e4cac040013733aca159d89
Processing simplejson-2.1.1.tar.gz
Running simplejson-2.1.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Ii_EU9/simplejson-2.1.1/egg-dist-tmp-79Fj1U
Adding simplejson 2.1.1 to easy-install.pth file
Installed /Library/Python/2.6/site-packages/simplejson-2.1.1-py2.6-macosx-10.6-universal.egg
Processing dependencies for simplejson
Finished processing dependencies for simplejson
$

And there you go!

Advertisements


10 Responses to “simplejson for Python on Mac OS X”

  1. It was lovely I spent half day trying anything.

    MAC OS LEOPARD 10.5.8

  2. 2 Klaus

    Thanks a lot for this! I was looking for an app to post with in Tumblr, I found http://www.opentumblr.com/ but it requires SimpleJson. Your tip helped me to install it 🙂

  3. Tiger (OS X 10.7) ships with Python 2.7.1 and Snow Leopard (OS X 10.6) ships with Python 2.6.something, so they already contain simplejson as the built-in json library. So replace “import simplejson as json” with “import json”, or better yet, figure out how to conditionally import the correct library depending on the Python version. (Suggestions on how to do this gratefully accepted.)

  4. @Steve: How about attempting to import in libraries in order of preference, but wrapping each import attempt in a try…except block?

  5. Searching for simplejson
    Reading http://pypi.python.org/simple/simplejson/
    Reading http://undefined.org/python/#simplejson
    Reading http://github.com/simplejson/simplejson
    Best match: simplejson 2.3.2
    Downloading http://pypi.python.org/packages/source/s/simplejson/simplejson-2.3.2.tar.gz#md5=0863e016f682f06ead07dd9efad95194
    Processing simplejson-2.3.2.tar.gz
    Running simplejson-2.3.2/setup.py -q bdist_egg –dist-dir /tmp/easy_install-kv2vwg/simplejson-2.3.2/egg-dist-tmp-5bwBpC
    unable to execute gcc-4.2: No such file or directory
    ***************************************************************************
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Failure information, if any, is above.
    I’m retrying the build without the C extension now.
    ***************************************************************************
    zip_safe flag not set; analyzing archive contents…
    simplejson.tests.__init__: module references __file__
    ***************************************************************************
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Plain-Python installation succeeded.
    ***************************************************************************
    Adding simplejson 2.3.2 to easy-install.pth file

    Installed /Library/Python/2.6/site-packages/simplejson-2.3.2-py2.6.egg
    Processing dependencies for simplejson
    Finished processing dependencies for simplejson

    how to avoid this warnings?

    • Looks like your system is trying to compile the C extension but is failing to find the gcc compiler. On a system like Ubuntu, install the build system with something like

      “sudo apt-get install build-essential python-dev”

      That should install the compiler and other necessary bits to compile the extension

  6. Retrieving data from the servers may be a tedious task, causing users to make heavy downloads, but that is again a much better option than
    backing no data at all. One therefore needs to keep formatting and
    re-formatting the i – Pod while switching from Mac to Windows
    etc. Another advantage that the Mac has is that you can increase your productivity
    when working on multiple programs because it
    is a lot faster and easier.

  7. Hello, i feel that i noticed you visited my blog so i came to go back the favor?.I’m
    attempting to in finding issues to enhance my site!I suppose its adequate to use a
    few of your ideas!!


  1. 1 コンテンツ・プランナーブログ » Blog Archive » TEDのビデオダウンロードに、日本語字幕(のJSONファイル)ダウンロードリンクを付けるブックマークレット
  2. 2 Python:how to add json library – IT Sprite

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: