[mod_python] python_handler: Can't get/create interpreter

Graham Dumpleton graham.dumpleton at gmail.com
Thu Feb 26 17:04:11 EST 2009


2009/2/27 Fred <dofre1680 at gmail.com>:
> Hello,
>
> maybe i have a bad mod_python install on a RHEL 4.5.
>
> I compile apache, mod_python and python, and install all  inside /freeware
> (it's a customer need).
> - /freeware/python-2.5.4/
> - /freeware/apache-2.2.6/
> When run, apache use a linux user call "web".
>
> Version :
> - apache 2.2.6
> - mod_python 3.3.1
> - python 2.5.1 (and test with the last 2.5.4)
>
> I try this example ( because i have some error with the Pylons application
> that i have to install) :
> http://www.modpython.org/live/current/doc-html/inst-testing.html
>
> When i try to access  to http://server/test/mptest.py i have a 500 server
> error.
>
> When i look at log i have (for each request) :
> [Thu Feb 26 19:46:29 2009] [error] [client X.X.X.X] python_handler: Can't
> get/create interpreter

Most likely because you have multiple versions of Python installed in
different root locations and when mod_python tries to initialise the
Python interpreter it is finding the root directory for the wrong one
and so cannot find the installed files for the correct one.

> this the only message inside error log....
>
> I try to re compil apache mod_python and python but i don't find any
> solution.
>
> I try the same thing with a distribution packages (python, mod_python and
> apache) install on ubuntu hardy and it's works.... (just to say that i'm not
> too stupid)!
>
> I have nos idea... this my virtual host apache.conf content include inside
> the main conf file :
> <VirtualHost *:80>
>     ServerAdmin webmaster at dummy-host.example.com
>     DocumentRoot "/dataweb/sws"
>     ServerName dns
>     ErrorLog "/dataweb/sws/logs/sws-error_log"
>     CustomLog "/dataweb/sws/logs/sws-access_log" common
>
> <Directory /dataweb/sws/test>
>         Options None
>         AllowOverride None
>         Order allow,deny
>         Allow from all
>         AddHandler mod_python .py
>         PythonHandler mptest
>         PythonDebug On
>         #PythonPath "sys.path+['/freeware/python-2.5.4/bin']"

There is no reason you would want to add the 'bin' directory to PythonPath.

> </Directory>
> SetEnv LD_LIBRARY_PATH /freeware/python-2.5.4/lib/python2.5/:/freeware/lib/

This SetEnv will do nothing for mod_python code.

>
> </VirtualHost>
>
> need help please.

Find the 'envars' file in same directory as 'httpd' for Apache which
is being used and add:

  PYTHONHOME=/freeware/python-2.5.4
  export PYTHONHOME

The file should be present if compiled Apache from source code. If you
are using a package Apache then it may not exist because they screwed
with Apache layouts. In that case you have to find the right init.d
startup file for Apache and hack it into there.

Restart Apache.

BTW, if using a web application which supports WSGI, you would be
better off using mod_wsgi. It is a bit more friendly as far as
overriding this sort of problem as one can set a directive in the
Apache configuration itself to indicate where Python is installed.
See:

  http://code.google.com/p/modwsgi/wiki/InstallationIssues#Multiple_Python_Versions

Just don't run mod_python and mod_wsgi at the same time though else
that directive will not work as mod_python still overrides things.

Graham



More information about the Mod_python mailing list