Django,mod_wsgi和虚拟环境 [英] Django, mod_wsgi and virtual env

查看:139
本文介绍了Django,mod_wsgi和虚拟环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用apache,mod_wsgi,virtual env设置Django



我有一个虚拟环境,我想在这里使用: [Missleading name - long story!]
/ home / andy / Dev / python / async-mongo /



我下载了 mod_wsgi 并以root身份使用virtual_env进行编译


./ configure --with-python = / home / andy / Dev / python / async-mongo / bin / python


我以root身份运行:


make install


我设置了WSGIPythonHome&路径在http.conf

  WSGIPythonHome / home / andy / dev / python / async-mongo / 
WSGIPythonPath / home /andy/dev/python/async-mongo/lib/python2.6/site-packages
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

我想我按照 http://code.google.com/p/modwsgi/wiki/VirtualEnvironments



当我运行Hello World应用程序时, strong> work

  def application(environ,start_response):
status ='200 OK'
output ='Hello World!'
response_headers = [('Content-type','text / plain'),
('Content-Length',str(len(输出))) ]
start_response(status,response_headers)

return [output]

当我尝试导入模块时,失败

  import sys;引发异常(sys.path)
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)
print>> sys.stderr,'sys.prefix =%s'%repr(sys.prefix)
print>> sys.stderr,'sys.path =%s'%repr(sys.path)
return [output]

我在apache日志中看到的错误是:


[Fri Mar 30 15:09:53 2012] [通知] Apache / 2.2.20(Ubuntu)mod_wsgi / 3.3 Python / 2.6.7配置 - 恢复正常操作


... .....


异常:['/ home / andy / dev / python / async-mongo',
' /home/andy/dev/python/async-mongo/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg',
'/ home / andy / dev / python / async -mongo / lib / python2.6 / site-packages / pip-1.0.2-py2.6.egg',
'/home/andy/dev/python/async-mongo/lib/python2.6/ site-packages / txmongo-0.3-py2.6-linux-i686.egg',
'/home/andy/dev/python/async-mongo/lib/python2.6',
'/ home / andy / dev / python / async-mongo / lib / python2.6 / plat-linux2',
'/home/andy/dev/python/async-mongo/lib/python2.6/lib-tk ',
'/ home / andy / dev / python / async- mongo / lib / python2.6 / lib-old',
'/home/andy/dev/python/async-mongo/lib/python2.6/lib-dynload',
'/ usr / lib / python2.6','/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/ home / andy /dev/python/async-mongo/lib/python2.6/site-packages']


我猜想某处某处我仍然引用旧的系统级python,但我不明白在哪里。如何解决这个问题?

解决方案

你在这里提出例外:

  import sys;提高异常(sys.path)


I'm setting up Django with apache, mod_wsgi, virtual env

I have a virtual env that I want to use here: [Missleading name - long story!] /home/andy/Dev/python/async-mongo/

I downloaded mod_wsgi and compiled it with virtual_env as root

./configure --with-python=/home/andy/Dev/python/async-mongo/bin/python

I ran as root:

make install

I setup WSGIPythonHome & Path in http.conf

WSGIPythonHome /home/andy/dev/python/async-mongo/
WSGIPythonPath /home/andy/dev/python/async-mongo/lib/python2.6/site-packages
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

I think I followed the instructions at http://code.google.com/p/modwsgi/wiki/VirtualEnvironments

When I run the 'Hello World' app it works

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]

When I try to import a module it fails:

import sys; raise Exception(sys.path)
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)
    print >> sys.stderr, 'sys.prefix = %s' % repr(sys.prefix)
    print >> sys.stderr, 'sys.path = %s' % repr(sys.path)
    return [output]

The error I see in the apache logs is:

[Fri Mar 30 15:09:53 2012] [notice] Apache/2.2.20 (Ubuntu) mod_wsgi/3.3 Python/2.6.7 configured -- resuming normal operations

........

Exception: ['/home/andy/dev/python/async-mongo', '/home/andy/dev/python/async-mongo/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg', '/home/andy/dev/python/async-mongo/lib/python2.6/site-packages/pip-1.0.2-py2.6.egg', '/home/andy/dev/python/async-mongo/lib/python2.6/site-packages/txmongo-0.3-py2.6-linux-i686.egg', '/home/andy/dev/python/async-mongo/lib/python2.6', '/home/andy/dev/python/async-mongo/lib/python2.6/plat-linux2', '/home/andy/dev/python/async-mongo/lib/python2.6/lib-tk', '/home/andy/dev/python/async-mongo/lib/python2.6/lib-old', '/home/andy/dev/python/async-mongo/lib/python2.6/lib-dynload', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/home/andy/dev/python/async-mongo/lib/python2.6/site-packages']

I am guessing that somewhere somehow I am still referencing the old system level python but I can not understand where. How can I fix this?

解决方案

You are raising an exception here:

import sys; raise Exception(sys.path)

这篇关于Django,mod_wsgi和虚拟环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆