试图开始mod_wsgi的金字塔应用程序时无模块命名部署(No module named deplo

2019-08-31 21:07发布

尝试使用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以确保它是从我所期望的文件加载...

现在如果我开始从pserve应用

$ /bin/pserve app/development.ini --reload

该应用程序已成功启动,下面控制台日志

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

我也尝试进入蟒蛇直接导入paster.py,没问题,以及

$ 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
>>>

权限应该是罚款,以及

$ 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__

通过访问Apache的网站的时候打印输出是/usr/local/lib/python2.6/dist-packages/paste ,不是的virtualenv。 我加入,我可以在网上细指向我在virtualenv中的所有例子pyramid.wsgi还有pythonpath在Apache的配置文件,但很明显,我仍然没有得到它的权利。 还有什么地方我试试吗?

Answer 1:

终于解决了。 从控制台登录很明显,在我的主要Python安装/usr/local/lib有一个paste安装不具有模块deploy处理函数定义。

RedBaron的评论设置WSGIPythonHome工作,但问题是我有多个应用程序,所以我不能只是点WSGIPythonHome在全球范围内特定应用的virtualenv中。

总之,我所经历mod_wsgi上的virtualenv文档再次( 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')


Answer 2:

在我的情况下,在虚拟环境中重新安装PasteDeploy解决了问题,不知道为什么,虽然。



Answer 3:

该错误将表明,未安装PasteDeploy包。

  • https://pypi.python.org/pypi/PasteDeploy


文章来源: No module named deploy when trying to start pyramid app with mod_wsgi