开发者

Problem Install and Run psycopg2 + Windows + Apache2 + mod_wsgi

开发者 https://www.devze.com 2022-12-18 15:47 出处:网络
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

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.


I am able to solve the problem, by moving python script outside htdocs

WSGIScriptAlias /wsgi "C:/wsgi/"

<Directory "C:/wsgi">
    AllowOverride None
    Options None
    Order deny,allow
    Allow from all
</Directory>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号