Installing mod_python on mac os 10.4.7

7

7stud

The mod_python manual says this under section 2.1 Prerequisites:

------
In order to compile mod_python you will need to have the include files
for both Apache and Python, as well as the Python library installed on
your system. If you installed Python and Apache from source, then you
already have everything needed. However, if you are using prepackaged
software (e.g. Red Hat Linux RPM, Debian, or Solaris packages from
sunsite, etc) then chances are, you have just the binaries and not the
sources on your system. Often, the Apache and Python include files and
libraries necessary to compile mod_python are part of separate
``development'' package. If you are not sure whether you have all the
necessary files, either compile and install Python and Apache from
source, or refer to the documentation for your system on how to get
the development packages.
-----

I installed Apache from source using these instructions:

http://switch.richard5.net/isp-in-a-box-v2/installing-apache-on-mac-os-x/

but I used a package to install python 2.4. The package was from
here:

http://www.pythonmac.org/packages/

and it's a "Universal binary version of Python that runs natively on
PPC and Intel systems."

But my mac came with Python 2.3.5 pre-installed, so I wonder if I
already have the necessary "include files for both Apache and Python,
as well as the Python library" already installed.
 
G

Graham Dumpleton

Themod_pythonmanual says this under section 2.1 Prerequisites:

------
In order to compilemod_pythonyou will need to have the include files
for both Apache and Python, as well as the Python library installed on
your system. If you installed Python and Apache from source, then you
already have everything needed. However, if you are using prepackaged
software (e.g. Red Hat Linux RPM, Debian, or Solaris packages from
sunsite, etc) then chances are, you have just the binaries and not the
sources on your system. Often, the Apache and Python include files and
libraries necessary to compilemod_pythonare part of separate
``development'' package. If you are not sure whether you have all the
necessary files, either compile and install Python and Apache from
source, or refer to the documentation for your system on how to get
the development packages.
-----

I installed Apache from source using these instructions:

http://switch.richard5.net/isp-in-a-box-v2/installing-apache-on-mac-o...

but I used a package to install python 2.4. The package was from
here:

http://www.pythonmac.org/packages/

and it's a "Universal binary version of Python that runs natively on
PPC and Intel systems."

But my mac came with Python 2.3.5 pre-installed, so I wonder if I
already have the necessary "include files for both Apache and Python,
as well as the Python library" already installed.

Have you actually tried to install mod_python? That would be the
quickest way of finding out.

Because you are using an alternate Apache than the OS supplied one,
you will need to use the --with-apxs option to configure when building
Python. Unless you really need Python 2.4, it is easier to use the OS
supplied version of Python. If you must use an alternate version, use
the --with-python option to configure for mod_python to tell it which
version. Depending on where that Python version is installed, you may
also have to fiddle the Apache 'envvars' file as well to get it to
work.

Graham
 
G

Graham Dumpleton

Have you actually tried to install mod_python? That would be the
quickest way of finding out.

Because you are using an alternate Apache than the OS supplied one,
you will need to use the --with-apxs option to configure when building
Python.

Whoops, --with-apxs option is to configure for mod_python, not Python.
 
7

7stud

Whoops, --with-apxs option is to configure formod_python, not Python.

Hi,

Thanks for the response. Sorry, I didn't respond in a timely manner.

I thought I would give your suggestion a shot and just try installing
mod_python and see what happens, so I installed mod_python 3.3.1 with
this command:

$ ./configure --with-apxs=/Library/Apache2/bin/apxs

Here is the output:

--------
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for ar... ar
checking for a BSD-compatible install... /usr/bin/install -c
checking whether make sets $(MAKE)... yes
checking for main in -lm... yes
checking for an ANSI C-conforming const... yes
checking your blood pressure... a bit high, but we can proceed
configure: checking whether apxs is available...
checking for --with-apxs... /Library/Apache2/bin/apxs executable, good
checking Apache version... 2.2.4
checking for Apache libexec directory... /Library/Apache2/modules
checking for Apache include directory... -I/Library/Apache2/include
checking for --with-python... no
checking for python... /Library/Frameworks/Python.framework/Versions/
Current/bin/python
checking Python version... 2.4
checking Python install prefix... /Library/Frameworks/Python.framework/
Versions/2.4
checking checking where python libraries are installed... /Library/
Frameworks/Python.framework/Versions/2.4/lib/python2.4
checking what libraries Python was linked with... -framework
Python -ldl
checking linker flags used to link Python...
checking where Python include files are... -I/Library/Frameworks/
Python.framework/Versions/2.4/include/python2.4
checking for --with-python-src... no
checking for --with-mutex-dir... no
Using MUTEX_DIR /tmp
checking for --with-max-locks... no
Using 8 MAX_LOCKS.
checking for --with-flex... no
checking for flex... /usr/bin/flex
found /usr/bin/flex, we'll use this. Use --with-flex to specify
another.
checking flex version... configure: WARNING: Flex version 2.5.4 found.
Version 2.5.31 or greater is required. You can generally ignore
this
warning unless you need to regenerate psp_parser.c from
psp_parse.l.
If you do need regenerate psp_parser.c, use --with-flex to specify
the
location of the correct flex version. See the README for more
information.
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating Doc/Makefile
config.status: creating src/include/mod_python.h
config.status: creating test/Makefile
config.status: creating test/testconf.py
config.status: creating dist/setup.py
config.status: creating dist/Makefile
-----

So it looks like it installed fine--although I notice it picked up
python 2.4 and you said it was easier to install mod_python using the
pre-installed python 2.3.3.

Then I tried to test the installation following the test in the
mod_python manual, which says to add the following to Apache's
http.conf file:

<Directory /some/directory/htdocs/test>
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>

I did that, but when I started Apache, I got this error:
 
7

7stud

I'm using Apache 2.2.4 whose root is /Library/Apache2. My installation
of python 2.4 is here:

/Library/Frameworks/Python.framework/Versions/2.4/
/Library/Frameworks/Python.framework/Versions/Current/

"Current" is a link to the 2.4 directory:

----
$ ls -al /Library/Frameworks/Python.framework/Versions/
total 8
drwxr-xr-x 4 root admin 136 Mar 22 14:22 .
drwxr-xr-x 6 root admin 204 Mar 22 14:22 ..
drwxrwxr-x 12 root admin 408 May 2 22:59 2.4
lrwxr-xr-x 1 root admin 3 Apr 8 01:45 Current -> 2.4
----

And /usr/local/bin looks like this:

--------
$ ls -al /usr/local/bin

lrwxr-xr-x 1 root wheel 68 Apr 8 01:45
python -> ../../../Library/Frameworks/Python.framework/Versions/2.4/
bin/python

lrwxr-xr-x 1 root wheel 71 Apr 8 01:45
python2.4 -> ../../../Library/Frameworks/Python.framework/Versions/2.4/
bin/python2.4

lrwxr-xr-x 1 root wheel 69 Apr 8 01:45
pythonw -> ../../../Library/Frameworks/Python.framework/Versions/2.4/
bin/pythonw

lrwxr-xr-x 1 root wheel 72 Apr 8 01:45
pythonw2.4 -> ../../../Library/Frameworks/Python.framework/Versions/
2.4/bin/pythonw2.4

-----------
 
7

7stud

My PATH environment variable looks like this:

PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:/bin:/
sbin:/usr/bin:/usr/sbin:/usr/local/mysql/bin
 
G

Graham Dumpleton

Hi,

Thanks for the response. Sorry, I didn't respond in a timely manner.

I thought I would give your suggestion a shot and just try installing
mod_python and see what happens, so I installed mod_python 3.3.1 with
this command:

$ ./configure --with-apxs=/Library/Apache2/bin/apxs

Here is the output:

--------
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for ar... ar
checking for a BSD-compatible install... /usr/bin/install -c
checking whether make sets $(MAKE)... yes
checking for main in -lm... yes
checking for an ANSI C-conforming const... yes
checking your blood pressure... a bit high, but we can proceed
configure: checking whether apxs is available...
checking for --with-apxs... /Library/Apache2/bin/apxs executable, good
checking Apache version... 2.2.4
checking for Apache libexec directory... /Library/Apache2/modules
checking for Apache include directory... -I/Library/Apache2/include
checking for --with-python... no
checking for python... /Library/Frameworks/Python.framework/Versions/
Current/bin/python
checking Python version... 2.4
checking Python install prefix... /Library/Frameworks/Python.framework/
Versions/2.4
checking checking where python libraries are installed... /Library/
Frameworks/Python.framework/Versions/2.4/lib/python2.4
checking what libraries Python was linked with... -framework
Python -ldl
checking linker flags used to link Python...
checking where Python include files are... -I/Library/Frameworks/
Python.framework/Versions/2.4/include/python2.4
checking for --with-python-src... no
checking for --with-mutex-dir... no
Using MUTEX_DIR /tmp
checking for --with-max-locks... no
Using 8 MAX_LOCKS.
checking for --with-flex... no
checking for flex... /usr/bin/flex
found /usr/bin/flex, we'll use this. Use --with-flex to specify
another.
checking flex version... configure: WARNING: Flex version 2.5.4 found.
Version 2.5.31 or greater is required. You can generally ignore
this
warning unless you need to regenerate psp_parser.c from
psp_parse.l.
If you do need regenerate psp_parser.c, use --with-flex to specify
the
location of the correct flex version. See the README for more
information.
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating Doc/Makefile
config.status: creating src/include/mod_python.h
config.status: creating test/Makefile
config.status: creating test/testconf.py
config.status: creating dist/setup.py
config.status: creating dist/Makefile
-----

So it looks like it installed fine--although I notice it picked up
python 2.4 and you said it was easier to install mod_python using the
pre-installed python 2.3.3.

Then I tried to test the installation following the test in the
mod_python manual, which says to add the following to Apache's
http.conf file:

<Directory /some/directory/htdocs/test>
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>

I did that, but when I started Apache, I got this error:

Have you got an appropriate LoadModule directive in Apache
configuration to load the mod_python module? That you get this error
is indicative of mod_python module not being loaded. You can check the
Apache error logs to see if mod_python got loaded.

See:

http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking

for more help on debugging.

Graham
 
7

7stud

Have you got an appropriate LoadModule directive in Apache
configuration to load the mod_python module? That you get this error
is indicative of mod_python module not being loaded.

I checked and I don't have a LoadModule directive for mod_python in /
Library/Apache2/conf/httpd.conf. But I can't find a file called
mod_python.so anywhere on my computer, so I don't know what path to
use.

You can check the
Apache error logs to see if mod_python got loaded.

I checked both these error logs:

/Library/Apache2/logs/error_log
/Library/Apache2/logs/access_log

and there is no entry for yesterday when I tried to start Apache after
my mod_python install. I assume that was because Apache never started
up?
 
7

7stud

Have you got an appropriate LoadModule directive in Apache
configuration to load the mod_python module? That you get this error
is indicative of mod_python module not being loaded. You can check the
Apache error logs to see if mod_python got loaded.

See:

http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking

for more help on debugging.

That article says the LoadModule directive should be:
LoadModule python_module libexec/mod_python.so

I saw this note in /Library/Apache2/conf/http.conf

# Configuration and logfile names: If the filenames you specify for
many
# of the server's control files begin with "/" (or "drive:/" for
Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "/Library/Apache2" will be interpreted by the
# server as "/Library/Apache2/logs/foo.log".

I have this server root in /Library/Apache2/conf/httpd.conf:

ServerRoot "/Library/Apache2"

So in the Load Module directive, the actual path to the mod_python.so
file is:

/Library/Apache2/libexec/mod_python.so

But I checked and I don't have a /Library/Apache2/libexec directory.
 
G

Graham Dumpleton

That article says the LoadModule directive should be:


I saw this note in /Library/Apache2/conf/http.conf

# Configuration and logfile names: If the filenames you specify for
many
# of the server's control files begin with "/" (or "drive:/" for
Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "/Library/Apache2" will be interpreted by the
# server as "/Library/Apache2/logs/foo.log".

I have this server root in /Library/Apache2/conf/httpd.conf:

ServerRoot "/Library/Apache2"

So in the Load Module directive, the actual path to the mod_python.so
file is:

/Library/Apache2/libexec/mod_python.so

But I checked and I don't have a /Library/Apache2/libexec directory.

Run 'apxs' for the version of Apache you are using to work out what
the actual modules directory should be:

$ /usr/local/apache-2.2.4/bin/apxs -q LIBEXECDIR
/usr/local/apache-2.2.4/modules

If there is no mod_python.so in there then you can't have done the
mod_python install properly. Go back to the mod_python source code and
rerun:

sudo make install_dso

When you do that it will even tell you exactly what the LoadModule
line you should use is.

Also ensure you actually installed the Python module components of
mod_python. You can redo that by running:

sudo make install_py_lib

Graham
 
7

7stud

Run 'apxs' for the version of Apache you are using to work out what
the actual modules directory should be:

$ /usr/local/apache-2.2.4/bin/apxs -q LIBEXECDIR
/usr/local/apache-2.2.4/modules

If there is no mod_python.so in there then you can't have done the
mod_python install properly. Go back to the mod_python source code and
rerun:

sudo make install_dso

When you do that it will even tell you exactly what the LoadModule
line you should use is.

Also ensure you actually installed the Python module components of
mod_python. You can redo that by running:

sudo make install_py_lib

Graham

I posted *everything* I did to install mod_python in my second post.
I just discovered there are additional steps I should have done, i.e.
make and make install. After I did those steps, I looked at the
output and there were no obvious errors. I then proceeded with the
Testing section of the mod_python manual. I added the following
LoadModule directive to my httpd.conf file:

LoadModule python_module /Library/Apache2/modules/mod_python.so

and I added the following to http.conf(I created the directory ../
htdocs/modPythonPages):

<Directory /Library/Apache/htdocs/modPythonPages>
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>

Then I started apache and it started up normally. Then I created a
file called mptest.py in the ../htdocs/modPythonPages/ directory with
this in it:

from mod_python import apache

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

But when I type the following url in my browser's address bar:

http://localhost/modPythonPages/mptest.py

all the text in the file is displayed--not the message "Hello
World!". So I checked the Troubleshooting section, which said to add
the following to httpd.conf:

<Location /mpinfo>
SetHandler mod_python
PythonHandler mod_python.testhandler
</Location>

I did that, then restarted apache, and typed the following into my
browser's address bar:

http://localhost/mpinfo

and I got a page displaying lots of information about my
configuration, but I don't know how any of that helps me figure out
what is wrong.

I also get this with an interactive python session:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/mod_python/psp.py", line 21, in ?
import apache, Session, util, _psp
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/mod_python/apache.py", line 30, in ?
import _apache
ImportError: No module named _apacheTraceback (most recent call last):
File "<stdin>", line 1, in ?
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/mod_python/testhandler.py", line 26, in ?
from mod_python import apache, util
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/mod_python/apache.py", line 30, in ?
import _apache
ImportError: No module named _apache
According to your article here:

http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking

that output is as it should be. Following your article, I tried using
a .htaccess file instead of putting the <Directory> tags in
httpd.conf. I deleted the <Directory> tags I added to httpd.conf and
restarted apache, but the same thing happened when I tried to display
the page in my browser: the text in the file displayed instead of the
message.

So following along with your article, I added the following to
httpd.conf:

<Directory /Library/Apache2/htdocs/modPythonPages>
AllowOverride FileInfo
</Directory>

I restarted apache, but I got the same results when I tried to access
the page in my browser. BUT THEN...I somehow happened to do an:

$ls -al

on my modPythonPages directory and I got this:

drwxr-xr-x 5 autie admin 170 Jul 29 23:24 .
drwxrwxr-x 11 root admin 374 Jul 28 15:05 ..
-rw-r--r-- 1 me admin 65 Jul 29 23:18 .htaccess.txt
-rw-r--r-- 1 me admin 355 Jul 29 23:24 mptest.py

As you can see when I saved the file, my mac added the .txt
extension. Since my mac hides the files with a "." in front of them,
I couldn't what the .htaccess file looked like in Finder after I saved
the file--the file just disappeared. I can't find a way to make my mac
display the "." files in Finder.

So, I changed the name of the file:

$mv .htacces.txt .htaccess

and then I typed the following in my browser's address bar again:

http://localhost/modPythonPages/mptest.py

and this time I got the correct message:

mptest.py

Yeah! So is my install good? Why didn't the Directory tags in
httpd.conf work?
 
7

7stud

Yeah! So is my install good? Why didn't the Directory tags in
httpd.conf work?

Ok. I got the mod_python manual's Testing directions to work as
well. The Testing section actually says:

-------
Add the following Apache directives, which can appear in ... the main
server configuration file...and

****you will need to make sure the AllowOverride directive applicable
to this directory has at least FileInfo specified. (The default is
None, which will not work.)****

<Directory /some/directory/htdocs/test>
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>
(Substitute /some/directory above for something applicable to your
system, usually your Apache ServerRoot)
----------------

I'm not sure how they expect people to interpret that to mean that you
need to add(in my case):

<Directory /Library/Apache2/htdocs/modPythonPages>
AllowOverride FileInfo
</Directory>

to Apache's httpd.conf file. But, in any case when I add that, I get
the message "Hello World!" to display when I type:

http://localhost/modPythonPages/mptest.py

in my browser's address bar.
 
7

7stud

The Testing section of the mod_python manual says to add the following
to httpd.conf(with my directory structure):

<Directory /Library/Apache2/htdocs/modPythonPages>
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>

and your tutorial says to add this to httpd.conf:

---
<Directory /some/directory>
AllowOverride FileInfo
</Directory>
Replace "/some/directory" with the absolute pathname to the directory
in which the ".htaccess" file is located.
-------

and the mod_python Testing section also cryptically refers to that
addition, so is there any reason why you can't combine them into:


<Directory /Library/Apache2/htdocs/modPythonPages>
AllowOverride FileInfo
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>



It seems to work for me. I deleted the .htaccess file out of the ../
modPythonPages/ directory, I made that change to httpd.conf, I
restarted apache, and mptest.py displays the proper message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top