2010/1/29 yccheok <[email protected]>:
> 1) I try to setup a new web environment to host python + psycopg2
> code. Here are my steps :
>
> 2) Download http://modwsgi.googlecode.com/files/mod_wsgi-win32-ap22py26-3.0.so
>
> 3) Copy mod_wsgi-win32-ap22py26-3.0.so to C:\Program Files\Apache
> Software Foundation\Apache2.2\modules, and rename it as mod_wsgi.so
>
> Add the following new lines into C:\Program Files\Apache Software
> Foundation\Apache2.2\conf\httpd.conf
>
> LoadModule wsgi_module modules/mod_wsgi.so
> WSGIScriptAlias /wsgi/ "C:/Program Files/Apache Software Foundation/
> Apache2.2/htdocs/wsgi/"
>
> 4) Save a file named C:\Program Files\Apache Software Foundation
> \Apache2.2\htdocs\wsgi\myapp.py with the following content :
>
> def application(environ, start_response):
> status = '200 OK'
> output = 'Hello World!'
>
> response_headers = [('Content-type', 'text/plain'),
> ('Content-Length', str(len(output)))]
> start_response(status, response_headers)
>
> return [output]
>
> 5) Access using http://localhost/wsgi/myapp.py
>
> 6) Install
> http://www.stickpeople.com/projects/python/win-psycopg/psycopg2-2.0.13.win32-py2.6-pg8.4.1-release.exe
>
> 7) If I modify the file content to
>
> import psycopg2
>
> def application(environ, start_response):
> status = '200 OK'
> output = 'Hello World!'
>
> response_headers = [('Content-type', 'text/plain'),
> ('Content-Length', str(len(output)))]
> start_response(status, response_headers)
>
> return [output]
>
> I will get
>
> ImportError: No module named psycopg2
>
> How can I tell apache, I had install the psycopg2 module in C:
> \Python26
>
> 8) I run the following standalone script to show psycopg2 had been
> installed.
>
> import psycopg2
>
> print "Hello, World!"
>
> I run it using
>
> C:\Documents and Settings\yan-cheng.cheok\Desktop>mypython.py
> Hello, World!
>
> Seem my python environment is OK.
>
> Any suggestion?
This would be caused by four possibilities.
The first is that Apache is using a different Python to what you used
when you installed pyscopg2.
This might occur where you have multiple Python versions installed.
You may say you haven't installed more than one, but there are a few
Windows applications which contain their own Python installation. If
that Windows package was in your search path then it is possible that
psycopg2 installed into that Python installation and not the main
official one.
To check this, from your command line Python do:
import sys
print sys.prefix
Then for Apache, use WSGI script:
import sys
def application(environ, start_response):
status = '200 OK'
output = sys.prefix
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
This will validate that sys.prefix is same for both and that should be
using the same Python installation.
Second possibility is that you installed psycopg2 into a directory
other than the main Python installations site-packages directory and
that you have user specific PYTHONPATH or registry entries set to find
it. Because Apache runs as a different user it will not inherit your
user specific settings and so wouldn't look in the same locations.
>From command line Python do:
import sys
print sys.path
import psycopg2
print psycopg2.__file__
For WSGI script use:
import sys
def application(environ, start_response):
status = '200 OK'
output = str(sys.path)
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
and compare value of sys.path.
Third possibility is that Python wasn't installed properly for all
users and so machine registry entries related to it are missing, with
the default module search path it constructs not properly picking up
the site-packages directory where pscyopg2 is installed.
The test above for two where you look at sys.path may highlight this
sort of problem.
Fourth and final one is that pyscopg2, where ever it is installed, has
permissions on files such that the user that Apache service runs as
cannot read them.
So, if all three above check out okay then you need to start looking
at file system permissions on directories and files for where pyscopg2
is installed.
Please post the results of sys.prefix and sys.path for command line
Python and under Apache so can compare and validate.
Graham
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=en.