I am attempting to setup Django with an internal company server. (No exterior internet connection.)
Overlooking the server setup documentation it seems the "Running Django on a shared-hosting provider with Apache" method appears to become probably the most-prone to work in cases like this.
Here's the server information:
- Can't install
- no root access
- Server is SunOs 5.6
- Python 2.5
- I have installed Django (and flup) while using --prefix option (reading through again I most likely should have used --home, but right now it does not appear to matter)
I have added the
.htaccess file and
mysite.fcgi file to my root web directory as pointed out here.
After I run the mysite.fcgi script in the server I recieve my expected output (the right site HTML output). But, it will not when attempting to gain access to it from the browser.
It appears it might be an issue with the
PYTHONPATH setting since I am while using prefix option.
I have observed when I run
mysite.fcgi in the command-line without setting the
PYTHONPATH enviornment variable it throws the next error:
prompt$ python2.5 mysite.fcgi ERROR: No module named flup Unable to load the flup package. In order to run django as a FastCGI application, you will need to get flup from http://www.saddi.com/software/flup/ If you've already installed flup, then make sure you have it in your PYTHONPATH.
I have added sys.path.append(prefixpath) and os.environ['PYTHONPATH'] = prefixpath to
mysite.fcgi, but when I set the enviornment variable to become empty around the command-line then run
mysite.fcgi, I get the above mentioned error.
Here are a few command-line results:
>>> os.environ['PYTHONPATH'] = 'Null' >>> >>> os.system('echo $PYTHONPATH') Null >>> os.environ['PYTHONPATH'] = '/prefix/path' >>> >>> os.system('echo $PYTHONPATH') /prefix/path >>> exit() prompt$ echo $PYTHONPATH Null
It appears like Python is setting the variable OK, however the variable is just relevant within the script. Flup seems to become distributed being an .egg file, and my prediction would be that the egg implementation does not consider variables added by
os.environ['key'] = value (?) a minimum of when setting up through the
I am not too acquainted with .pth files, however it appears the easy-install.pth file is the one which indicates flup:
import sys; sys.__plen = len(sys.path) ./setuptools-0.6c6-py2.5.egg ./flup-1.0.1-py2.5.egg import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sy s.path[p:p]=new; sys.__egginsert = p+len(new)
It appears like it's doing something funky, anyway to edit this or add something to my code therefore it will discover flup?
Inside your configurations you need to point go actual egg file, not directory where egg file is situated. It will look something similar to:
Use a software application known as virtualenv. Based on the official package page, "virtualenv is really a tool to produce isolated Python conditions."
It'll take proper care of the
PYTHONPATH stuff for you personally making simple to use to properly install Django and flup.
Use site.addsitedir() not os.environ['PYTHONPATH'] or sys.path.append().
site.addsitedir translates the .pth files. Modifying os.environ or sys.path doesn't. Not inside a FastCGI atmosphere anyway.
#!/user/bin/python2.6 import site # adds a directory to sys.path and processes its .pth files site.addsitedir('/path/to/local/prefix/site-packages/') # avoids permissions error writing to system egg-cache os.environ['PYTHON_EGG_CACHE'] = '/path/to/local/prefix/egg-cache'