尝试在apache服务器上运行mod_wsgi时出错

时间:2018-09-02 19:01:00

标签: python flask apache2 mod-wsgi

我在 / var / www 中有一个Flask Project结构目录:

item-catalog-fullstacknd\
    itemCatalogApp.wsgi
    itemCatalogApp\
        __init__.py

这是上面的WSGI文件:

import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/item-catalog-fullstacknd/")
from itemCatalogApp import app as application
application.secret_key = 'Add your secret key' 

这是 /etc/apache2/sites-enabled/000-default.conf

WSGIPythonPath /var/www/item-catalog-fullstacknd/itemCatalogApp/
<VirtualHost *:80>
    WSGIScriptAlias / /var/www/item-catalog-fullstacknd/itemCatalogApp.wsgi

            <Directory /var/www/item-catalog-fullstacknd/itemCatalogApp>
                    Order allow,deny
                    Allow from all
            </Directory>

            Alias /static /var/www/item-catalog-fullstacknd/itemCatalogApp/static

            <Directory /var/www/item-catalog-fullstacknd/itemCatalogApp/static/>
                    Order allow,deny
                    Allow from all
            </Directory>

</VirtualHost>

我收到以下错误:

mod_wsgi (pid=17586): Exception occurred processing WSGI script '/var/www/item-catalog-fullstacknd/itemCatalogApp.wsgi'.
 Traceback (most recent call last):
   File "/var/www/item-catalog-fullstacknd/itemCatalogApp.wsgi", line 6, in <module>
     from itemCatalogApp import app as application
   File "/var/www/item-catalog-fullstacknd/itemCatalogApp/__init__.py", line 3, in <module>
     from flask import Flask, jsonify, render_template, request
 ImportError: No module named flask

我已经pip install文件中包含的所有模块。 我不知道该怎么办。

1 个答案:

答案 0 :(得分:1)

您可能已为其他python可执行文件安装了模块,而不是mod_wsgi默认使用的模块。要进行检查,请在您的WSGI文件的<开始>添加:

import sys
print(sys.executable)

然后打开外壳,运行python并在其中键入相同的代码。如果路径不同,则应指定WSGIPythonHome to point at the desired python executable