2

I am new to this whole python deal, and admit that I am half lost - don't know whether I am coming or going. So, here's the question and I hope someone can assist me.

I am running a RedHat system and by default, it has python 2.4 installed. I have a python script that gives me an error when attempting to import json.

I have checked my phpinfo and it shows that I have json version 1.2.1 (or something or other) - so why isn't Python recognizing that this json does exist? Is there a file that I need to edit to manually enter or edit where python looks for the json at, and if so, where?

I even tried installing simplejson and also python 3 - nothing has worked so far, and I have run out of hair to pull out.

Any help would be greatly appreciated - thanks in advance.

0

2 Answers 2

2

PHP is not Python and the fact that your PHP version supports JSON has no effect on your Python installation. The json module was introduced in Python 2.6.

You could try to install simplejson, but according to the documentation, it is only supported since Python 2.5. (should have read the whole question).

I would upgrade the Python version (most recent version is 2.7.2). You don't say why the installation of Python 3 didn't work, but maybe staying with the same branch (i.e. 2.7) will work out.

Sign up to request clarification or add additional context in comments.

17 Comments

With 2.4 you are missing a lot of very nice features. I also recommend upgrading if at all possible.
if I type python -v to check version - the default 2.4 comes up. If i type /opt/python3/bin/python3 -V, then i get version 3.2. But heres the part that has me confused about which version I am running - if I type python3 -V, I get command not found.
` /opt/python3/bin` is obviously not in your PATH
i am not sure what you mean - but what I posted is exactly what i type in my command line - and thats the result I get - i a in the home directory - but with root access - dont know if that makes any difference
In your home dir you have some form of a .profile, or .bash_profile, etc. It defines your environment. Currently that path is not in your PATH variable so your shell doesn't know to look there to resolve python3
|
0

python needs the python module for json, which is not the same as the php module for json.

There are some to pick from, e.g. you can use python-cjson, so make sure that this module is installed.

You can ask rpm about which packages are installed like this: rpm -qa | grep json

11 Comments

# rpm -qa | grep json - when inputting this - I get: uptrack-python-cjson-1.0.5-5.el5
what would be the correct import command to pull in this version of ppython-cjson instead
However, json is a standard module in Python 2.6, which means the script was written and tested for Python 2.6 or later. Even if some json module is installed and the script uses it, it seems quite probable that the script will fail in some other way because it was not written with Python 2.4 in mind.
ok - I am with you so far. So, how do I make my 3.2 install the default install instead of the 2.4
@user1257948: import cjson as json
|

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.