This question is based on 2 parts I think: (TL;DR at bottom)
1-How do I install libraries or modules for Python onto my webserver? I've already emailed my webhosts to ask if I have permissions to or if they need to, but so far I don't think they know what I'm talking about, so while I'm waiting for the next reply I'll ask here (There's absolutely no information on anything techier than FTP tutorials on their knowledgebase). Python is installed in usr/bin/, and my python scripts have to live in www/cgi-bin to be callable but if i want to add functionality I've no idea beyond this, having never done much back-end stuff like this to my website
2-Does anyone know of a good JSON library for Python 2.3.4? This is the version of Python my webhosts have installed (which i only found out through a system call on a python script), I've seen an old version of simplejson which says it's for this version, but obviously something that I can just upload to call without needing to install would be in开发者_Go百科finitely more awesome, or maybe there's just something better (I've already enquired about upgrading to 2.6, but I'm not holding my breath)
TL;DR: Have python 2.3.4 on webserver. Need JSON functionality for my python scripts hosted there. No clue.
To answer the 1st part:
Just download the src of the library and put it anywhere. Then, add the path to that directory to sys.path list. That's it. When you import the package, the compiler will be able to find it since it will look at all the dirs in the sys.path list.
Let's say u download the package py-json and put it in /usr/lib/
.
Then, in the beginning of your handler module, add:
sys.path.append("/usr/lib/")
then u can import py-json, like:
import py-json
or if u want to import one of its modules:
import py-json.modulename
You can use SimpleJSON. Since you run Python 2.3, you can try some old version, because the latest claims to be compatible with Python 2.5.
精彩评论