[Pythonmac-SIG] python path, cgi issues, import error

Daniel Thorpe danthorpe at gmail.com
Wed Mar 28 20:21:39 CEST 2007

Hi, I hoping someone can help me with a cgi / import error problem. I  
know it's not strictly MacPython related (although I am using Python,  
on a Mac), but I've looked all over the web, and most of the answers  
to this problem suggest checking your path. Which I've done.

Here are the details....

I'm trying to write a python cgi script which is located at http:// 
localhost/cgi-bin/python.cgi. In this script I need to import  
packages from /Volumes/Data/Users/dt05r/Documents/phd/trunk/code,  
specifically geostats.conversion. My directory tree looks something  
like this:

__init__.py							/Volumes/Data/Users/dt05r/Documents/phd/trunk/code/ 

My http://localhost/cgi-bin/python.cgi (which is in /Library/ 
WebServer/CGI-Executables) contains this code:

#!/usr/bin/env python
# Required header that tells the browser how to render the text.
print 'Content-type: text/html\n\n'
import cgi, cgitb
import os, os.path, sys
print os.environ.get("PYTHONPATH")
from geostats import *

this prints out the correct $PYTHONPATH, and then spits out an  

ImportError: No module named geostats
       args = ('No module named geostats',)

I'm setting the $PYTHONPATH using Apache, I have this in my httpd.conf:

     <Directory "/Library/WebServer/CGI-Executables">
     	SetEnv PYTHONPATH "/Volumes/Data/Users/dt05r/Documents/phd/ 
     	PassEnv PYTHONPATH
         AllowOverride None
         Options None
         Order allow,deny
         Allow from all

I've also made the python code I'm trying to import executable using  
chmod -R +x .

If anyone has any idea why I can't import this module - your help is  
much appreciated!


More information about the Pythonmac-SIG mailing list