472,805 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

installing mod_python -- sharing experiences

i would like to briefly share my experiences with
installing mod_python on a w2000 box. i must say that i
believe the installation process to be unnecessarily
complicated by the simple fact that the installer itself
seems to be buggy -- in my case, no combination of
mod_python 3.0.4, 3.1.2b and python 2.2.3, 2.3.3 ever
came to completion. rather, the installer would exit --
after an initial declaration of having successfully
found python in the registry -- with the words that it
'could not load python'. i now believe this may be due
to python being absent from ``path`` and a missing value
in ``pythonhome`` (see below), but on the other hand,
all my other package installations with this particular
installer brand had never given me any troubles. it
would be a nice thing if the installer was smart enough
to dispense some hints in such a case.

it is important to check that the correct python version
is selected for the respective version of mod_python --
as far as i can see, both 3.0.4 and 3.1.2b are built for
python 2.3, which at least in the former case is not so
clear from descriptions or filenames. whatever version
you downloaded, you can quickly check this by 1)
unpacking the ``*.exe`` file with a zip tool, 2) go to
the contained folder ``DATA``, open the binary
``mod_python.so`` in any text editor, and 3) search for
the string ``python2``. this should yield a single hit,
from which you can glean the expected version of the
python dll. since i never managed to finish the
installation process with the installer, i think it is
the best idea to then proceed like this:
1) simply grab that ``python_mod.so`` file and drop it
in the ``apache/modules`` folder; likewise, go to the
directory ``PURELIB/mod_python`` in the executable
archive and copy it as ``python/Lib/site-
2) in apaches ``httpd.conf``, do a test configuration
like this::

# NB.: When setting an alias, both the alias
# and the aliased location should end in a
# slash or avoid it.

Alias /mod_python0 "drive:/some/path/mod_python/test0"

<Directory "drive:/some/path/mod_python/test0">
Options Indexes
AddHandler python-program .py
PythonHandler myhandler
PythonDebug On

observe that ``.py`` does start with a dot -- this does
not seem to be essential, though.

one important point is that you had better make sure
that python scripts are not declared as cgi scripts in a
parent directory. if you absolutely need this, try
later, but for the moment it is important to understand
that the ``ExecCGI`` and the ``python-program``
declarations are enemies. -- restart apache (must be
version 2, btw, afaics), either from the services
management console, or, much better, from a terminal
window by saying

apache.exe -k restart

(if you have your apache installed as a service). the
terminal window method has the distinct advantage that
any error messages due to problems with the httpd.conf
do appear right in front of your eyes, instead of being
silently swallowed by the system. of course, you can
also simply start apache as an ordinary program with a
line like ::

apache -w -f drive:\path\to\apache\conf\httpd.conf
3) create .../mod_python/test0/myhandler.py and make
it contain something like this::

# -*- coding: utf-8 -*-

from mod_python import apache

def handler(req):

req.content_type = "text/plain"
req.write("Hello World!")
return apache.OK

observe that the ``import`` statement prohibits the
execution of this snippet as a script, since it causes
the import of a module that is only available from
``mod_python.so`` -- maybe someone can come up with a
good idea how to make mod_python web scripts executable
from the command line some day; developers will love
4) in case the directory where the pythonXX.dll is to be
found should *not* appear on the environment variable
``path``, apache will refuse to start and issue the
following message::

Cannot load drive/dir/Apache2/modules/mod_python.so
into server: The specified module could not be

this may be a problem with per-user python installations
that put the dll into the python directory, not into the
windows directory.
5) you also may want to consider setting the
``pythonhome`` environment variable -- while
experimenting, this solved my problems in one case, but
for some reason, i found myself unable to reproduce the
behavior later. anyhow, you'd simply type ::

set pythonhome=drive:\path\to\python

or create an entry in ``autoexec.bat``, or set the
variable in the system administration.
6) one user also mentioned insufficient access rights in
the scripts directory as a potential cause of
malfunction -- apache does ordinarily not run as a
common user, but under a special account that must be
granted execution access to the directories where you
deploy your web application (i did not have his problem,
but may be this is due to apache running with
administrator rights, which is not a brilliant idea to
7) enjoy.

Jul 18 '05 #1
1 2188
i should add that one must make sure that sufficient
rights are granted to whatever account the apache
service is run under to read and execute not only in the
web application directory, but also *in the python
directory* -- i guess this point is easily missed. as a
quick check whether this may be one of your problems
(which normally results in the message ``could not
import mod_python.apache`` in the apache errors log
file) you can =either= temporarily set the apache
service account to administrator (provided you have the
rights to do so) =or=, alternatively, go to the python
directory and grant the ``SYSTEM`` account execution
rights. of course, this does not work on fat32 volumes.
-- hope these tips in conjunction with my preceding
posting help people fly their apps,

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: ted | last post by:
Hello, I'm thinking about trying out mod_python 3.1 and was wondering if anyone could share their experiences with it. I use Jakarata Tomcat and Struts at work and I like the MVC pattern but...
by: Piet | last post by:
Hi there, I cannot install mod_python v3.1.3 on either Win2k/ActivePython 2.3.2 or WinMe/Python 2.3.4. When I run the Windows installer, I get the following error message: Traceback (most recent...
by: Dan | last post by:
I've been writing a server application in Python. The app listens on a socket and interfaces to a database. Now I'd like to write a web application to also access the database. It seems natural...
by: Neuruss | last post by:
I need help with this issue. All my attempts to get it up and running failed, and the documentation I found so far didn't help me at all. I'm trying to configure this components together: -...
by: Robert W. | last post by:
I'm embarking on a project that will have both a desktop application and a Pocket PC application. It seems logical to have as much code as possible sitting in a shared project, which would be...
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
by: Scott | last post by:
I am trying to get a mod_python application to read an existing PHP session. I need some data that was set in the session by the PHP application. I am using the mod_python Session class but even...
by: Jan Danielsson | last post by:
Hello all, I have written a web-based voting system (add question, add possible answers to that question, and let users vote) in python. It uses: - mod_python - postgreql (through psycopg2) ...
by: Ilias Lazaridis | last post by:
How to detect memory leaks of python programms, which run in an environment like this: * Suse Linux 9.3 * Apache * mod_python The problem occoured after some updates on the infrastructure....
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.