[mod_python] two installation issues w/ Python 2.0b1

Jeremy Hylton jeremy at beopen.com
Mon Sep 11 14:14:46 EST 2000


I installed mod_python for the first time this morning.  I'm just
learning how to use it.  I ran into a couple of configuration issues,
because I am using Python 2.0b1 on my system.

Issue #1 is that mod_python.c makes explicit reference to a Python
executable named python1.5.  This grabs an old version of Python on my
system and compilation fails because it can't find an include file.
If I replace "python1.5" with "python," it all works fine under Python
2.0.

-------------- next part --------------
*** src/modules/extra/mod_python.c	Mon Sep 11 13:01:20 2000
--- ../mod_python-2.0/src/mod_python.c	Mon May 22 08:14:39 2000
***************
*** 2526,2533 ****
   * MODULE-DEFINITION-START
   * Name: python_module
   * ConfigStart
!  PyVERSION=`python -c "import sys; print sys.version[:3]"`
!  PyEXEC_INSTALLDIR=`python -c "import sys; print sys.exec_prefix"`
   PyLIBP=${PyEXEC_INSTALLDIR}/lib/python${PyVERSION}
   PyLIBPL=${PyLIBP}/config
   PyLIBS=`grep "^LIB[SMC]=" ${PyLIBPL}/Makefile | cut -f2 -d= | tr '\011\012\015' '   '`
--- 2526,2533 ----
   * MODULE-DEFINITION-START
   * Name: python_module
   * ConfigStart
!  PyVERSION=`python1.5 -c "import sys; print sys.version[:3]"`
!  PyEXEC_INSTALLDIR=`python1.5 -c "import sys; print sys.exec_prefix"`
   PyLIBP=${PyEXEC_INSTALLDIR}/lib/python${PyVERSION}
   PyLIBPL=${PyLIBP}/config
   PyLIBS=`grep "^LIB[SMC]=" ${PyLIBPL}/Makefile | cut -f2 -d= | tr '\011\012\015' '   '`
-------------- next part --------------

Issue #2: The installation of modules in site-packages is
significantly easier under Python 2.0, because you can count on
distutils being installed.  Instead of using compileall.py, I wrote a
simple setup.py script that I would recommend for inclusion in the
next release.

-------------- next part --------------
#!/usr/bin/env python

from distutils.core import setup

setup(name = "mod_python",
      version = "2.0",
      author = "Gregory Trubetskoy",
      author_email = "grisha at modpython.org",
      packages = ["mod_python"],
      package_dir = {'': 'lib/python'},
      )
-------------- next part --------------

I also had a problem running the mptest.py script described in the
documentation; so I'm reporting it as recommended by the docs.  I
don't know if the problem results from my use of Python 2.0 or being
confused about how to configure things or something else entirely.

If I run the generic mod_python install, I get an error when I tried
to load http://localhost:8080/test/mptest.py.

    ERROR mod_python: "PythonHandler mptest"

    Traceback (most recent call last):

      File
      "/usr/local/lib/python2.0/site-packages/mod_python/apache.py",
      line 103, in Dispatch 
        module = import_module(module_name, req)

      File
      "/usr/local/lib/python2.0/site-packages/mod_python/apache.py",
      line 246, in import_module 
        exec "import " + module_name

      File "<string>", line 1, in ?

    ImportError: No module named mptest

The problem, near as I can tell, is that the mod_python.apache inserts
"." at the head of sys.path -- but the current working directory is
"/".  There's no way "." would work unless apache or mod_python
explicitly changed the cwd to the directory that contains mptest.py.

So I changed the relevant lines in apache.py to do that:

    # unless pythonpath is set explicitely
    if pythonpath is not None:
        sys.path = eval(pythonpath)
    else:
        dir, file = os.path.split(req.filename)
        sys.path.insert(0, dir)
##        # add '.' to sys.path 
##        if '.' not in sys.path:
##            sys.path[:0] = ['.']

Now it works.  The test script prints "Hello World!"

Any idea what went wrong?  Have I done something naive in my
configuration of Apache or mod_python?  What component is responsible
for making the chdir call?

-- Jeremy Hylton <http://www.python.org/~jeremy/>


More information about the Mod_python mailing list