尝试使用mod_wsgi启动金字塔应用程序时,没有名为deploy的模块

时间:2013-04-23 04:30:49

标签: python apache mod-wsgi pyramid paster

第一次尝试使用mod_wsgi作为我的金字塔应用,但是当我尝试访问该网站时,我不断获得ImportError: No module named deploy

/etc/apache2/sites-available/domain.com

<VirtualHost *:80>  
    ServerName domain.com
    ServerAlias www.domain.com
    ServerAdmin admin@domain.com
    DocumentRoot /data/app
    ErrorLog /data/app/apache_error.log

    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    WSGIDaemonProcess pyramid user=www-data group=www-data \
        processes=2 threads=4 \
        python-path=/data/app/lib/python2.6/site-packages/
    WSGIScriptAlias / /data/app/pyramid.wsgi

    <Directory /data/app>
        WSGIProcessGroup pyramid
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
/data/app/pyramid.wsgi

中的

venv = '/data/app/bin/activate_this.py'
execfile(venv, dict(__file__=venv))

ALLDIRS = ['/data/app/lib/python2.6/site-packages']

import sys, site, os

site.addsitedir('/data/app/lib/python2.6/site-packages')

sys.path.append('/data/app/app')
os.environ['PYTHON_EGG_CACHE'] = '/data/app/python-eggs'

from pyramid.paster import get_app, setup_logging
ini_path = '/data/app/app/development.ini'
setup_logging(ini_path)
application = get_app(ini_path, 'main')

当我尝试在浏览器中访问domain.com时,出现The server encountered an internal error or misconfiguration and was unable to complete your request错误。这是打印出我的错误日志

[Mon Apr 22 20:43:13 2013] [error] test
[Mon Apr 22 20:43:13 2013] [error] mod_wsgi (pid=6795): Target WSGI script '/data/app/pyramid.wsgi' cannot be loaded as Python module.
[Mon Apr 22 20:43:13 2013] [error] mod_wsgi (pid=6795): Exception occurred processing WSGI script '/data/app/pyramid.wsgi'.
[Mon Apr 22 20:43:13 2013] [error] Traceback (most recent call last):
[Mon Apr 22 20:43:13 2013] [error]   File "/data/app/pyramid.wsgi", line 30, in <module>
[Mon Apr 22 20:43:13 2013] [error]     from pyramid.paster import get_app, setup_logging
[Mon Apr 22 20:43:13 2013] [error]   File "/data/app/lib/python2.6/site-packages/pyramid-1.4-py2.6.egg/pyramid/paster.py", line 3, in <module>
[Mon Apr 22 20:43:13 2013] [error]     from paste.deploy import (
[Mon Apr 22 20:43:13 2013] [error] ImportError: No module named deploy

请注意,第一行上的test打印来自print 'test'顶部的手动添加/data/app/lib/python2.6/site-packages/pyramid-1.4-py2.6.egg/pyramid/paster.py,以确保从我预期的文件中加载$ /bin/pserve app/development.ini --reload 。 ..

现在如果我从pserve启动应用程序

test
Starting subprocess with file monitor
test
Starting server in PID 9132.
serving on http://0.0.0.0:6543

应用程序成功启动,控制台日志在

下面
$ cd /data/app/lib/python2.6/site-packages/pyramid-1.4-py2.6.egg/pyramid/
$ /data/app/bin/python
Python 2.6.5 (r265:79063, Oct  1 2012, 22:04:36)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyramid.paster as p
test
>>> print p.__file__
/data/app/lib/python2.6/site-packages/pyramid-1.4-py2.6.egg/pyramid/paster.pyc
>>>

我也试过直接进入python导入paster.py,也没问题

$ ls /data/app -l
-rw-rw-r-- 1 root www-data 4148 2013-04-22 21:06 apache_error.log
drwxrwsr-x 4 root www-data 4096 2013-04-22 12:05 app
drwxrwsr-x 2 root www-data 4096 2013-04-22 12:04 bin
drwxrwsr-x 2 root www-data 4096 2013-04-22 11:58 include
drwxrwsr-x 3 root www-data 4096 2013-04-22 11:58 lib
-rwxrwxr-x 1 root www-data  893 2013-04-22 12:23 pyramid.wsgi
drwxrwsr-x 2 root www-data 4096 2013-04-22 12:07 python-eggs

权限也应该没问题

www-data
我错过了什么?谢谢!

修改 $ ps aux | grep apache2 root 2599 0.0 1.4 185200 14552 ? Ss 10:00 0:02 /usr/sbin/apache2 -k start www-data 9064 0.0 0.8 185664 8940 ? Sl 21:06 0:00 /usr/sbin/apache2 -k start www-data 9065 0.0 0.8 185664 8940 ? Sl 21:06 0:00 /usr/sbin/apache2 -k start www-data 9095 0.0 1.1 187292 11388 ? S 21:06 0:00 /usr/sbin/apache2 -k start www-data 9096 0.0 1.1 187292 11388 ? S 21:06 0:00 /usr/sbin/apache2 -k start www-data 9097 0.0 1.0 186768 10472 ? S 21:06 0:00 /usr/sbin/apache2 -k start www-data 9098 0.0 1.0 186768 10472 ? S 21:06 0:00 /usr/sbin/apache2 -k start www-data 9099 0.0 1.0 186768 10472 ? S 21:06 0:00 /usr/sbin/apache2 -k start root 9189 0.0 0.0 7624 912 pts/0 S+ 21:42 0:00 grep apache2 也是正确的用户

print 'test'
根据格雷厄姆的建议

修改,我用paste.py替换了import paste as p print p.__path__

/usr/local/lib/python2.6/dist-packages/paste

通过apache访问网站时的打印输出是pyramid.wsgi,而不是virtualenv。我已经添加了所有可以在线使用的示例,以指向pythonpath中的virtualenv以及apache配置文件中的{{1}},但显然我仍然没有做到正确。我还在哪里尝试?

3 个答案:

答案 0 :(得分:3)

终于解决了。从控制台日志中可以看出,/usr/local/lib中我的主要python安装已经安装了paste模块,没有定义deploy处理程序。

RedBaron对设置WSGIPythonHome的评论有效,但问题是我有多个应用,所以我不能只将WSGIPythonHome全局指向特定应用的virtualenv。

无论如何,我再次浏览了virtualenv上的mod_wsgi个文档(https://code.google.com/p/modwsgi/wiki/VirtualEnvironments#Baseline_Environment)并看到WSGIPythonHome应指向“处女环境”。字面上

$ virtualenv --no-site-packages BASELINE

然后指向WSGIPythonHome

WSGIPythonHome /usr/local/pythonenv/BASELINE

并将WSGIDaemonProcess指向我的应用程序的特定virtualenv(我在开始时已经做过)

经验教训:更多关注文档......


最后,我的pyramid.wsgi可以大大简化为以下

import os
os.environ['PYTHON_EGG_CACHE'] = '/data/app/python-eggs'

from pyramid.paster import get_app, setup_logging
ini_path = '/data/app/app/development.ini'
setup_logging(ini_path)
application = get_app(ini_path, 'main')

答案 1 :(得分:2)

在我的案例中,在虚拟环境中重新安装PasteDeploy修复了问题,但不确定原因。

答案 2 :(得分:1)

该错误表示未安装PasteDeploy包。