2

I'm doing some introductory work with django which seems really easy (and fun) so far but I have been doing all this from Python 2.6 which I installed in /opt/local (RedHat 5.3) because the python that came with redhat was 2.4. I set up a symlink:

/usr/bin/python2.6 -> /opt/local/bin/python

and I have been using that for all the django stuff so far; i.e.

> python2.6 manage.py runserver

However, when I try to move on to production mode, mod_python isn't using the right version of python:

Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch
    log=debug)

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 461, in import_module
    f, p, d = imp.find_module(parts[i], path)

ImportError: No module named django

I have this in my /etc/httpd/conf/httpd.conf:

<Location "/chat">
 SetHandler python-program
 PythonHandler django.core.handlers.modpython
 SetEnv DJANGO_SETTINGS_MODULE chat.settings
 PythonDebug On
 PythonPath "['/www/django/chat', '/opt/local/lib/python2.6/site-packages/django/'] + sys.path"
</Location>

So my question is, how do I make mod_python look for python2.6 instead of python?

jamesbtate
  • 1,359
  • 3
  • 19
  • 25

3 Answers3

4

You would have to rebuild mod_python against your python2.6 installation. Since mod_python loads python as a library the version is fixed at compile time.

Geoff Reedy
  • 34,891
  • 3
  • 56
  • 79
3

Don't use mod_python any more. mod_wsgi is the recommended way to deploy Django appliations now.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • 2
    I'm going to be pedantic. You're right. mod_wsgi is the recommended way. There may be a few situations where mod_python might be the better option. Firstly, if you have an older distro of one of the enterprise linuxes and your apache is statically linked and you do not have the option to recompile. It might be easier to get a pre-compiled mod-python from yum repos. If you wanted to decouple python and apache entirely, and speed was not a concern, you could use fastcgi. Just saying, recommended isn't always the *best*. – Rokujolady Nov 26 '12 at 20:33
  • This apparently unhelpful answer was what I needed to read to realize I had a lingering installation of mod_python that I had to remove. – Liz Av Jul 14 '15 at 19:25
2

You can rebuild mod_python to link against libpython dynamically so that you can pick up version updates to your libpython but it takes some chicanery.

You will need to edit the configure script for mod_python as follows (remove -L${PyLIBPL}):

$ diff  configure.orig configure 
<   LDFLAGS="${LDFLAGS} -L${PyLIBPL}"
---
>   LDFLAGS="${LDFLAGS}"

Then do

configure --with-python=/path/to/bin/python ; make; make install dance.

When you run:

ldd mod_python.so

you should see a line that looks like:

libpython2.6.so.1.0 => /usr/lib/libpython2.6.so.1.0

Gareth Simpson
  • 36,943
  • 12
  • 47
  • 50
shreddd
  • 10,975
  • 9
  • 33
  • 34