简体   繁体   English

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

[英]Error trying to run mod_wsgi on a apache server

I have a Flask Project structure directory inside /var/www : 我在/ var / www里面有一个Flask Project结构目录:

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

This is th WSGI file above: 这是上面的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' 

This is the /etc/apache2/sites-enabled/000-default.conf 这是/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>

And I am getting the following error: 我收到以下错误:

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

I already pip install all the modules contained in the requirements.txt file. 我已经pip installrequirements.txt文件中包含的所有模块。 I have no idea what to do anymore. 我不知道该怎么办了。

It's possible that you've installed modules for a different python executable, not the one that your mod_wsgi uses by default. 您可能已经为其他python可执行文件安装了模块,而不是mod_wsgi默认使用的模块。 To check that, add to the beggining of your WSGI file: 要检查,添加到您的WSGI文件的beggining:

import sys
print(sys.executable)

Then, open shell, run a python and type the same code there. 然后,打开外壳,运行python并在其中键入相同的代码。 If path is different, you should specify WSGIPythonHome to point at the desired python executable . 如果path不同,则应指定WSGIPythonHome指向所需的python可执行文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM