首页 文章

mod_wsgi与Flask app:ImportError:没有名为flask的模块

提问于
浏览
1

在CentOS 6.4中,我在/ var / www / html / venv文件夹中创建了python虚拟环境 . 然后在激活虚拟环境后,我为我的flask应用程序安装了所有必需的python库 . 我检查过,Flask库位于/var/www/html/venv/lib/python2.7/site-packages文件夹中 . 我已经安装并加载了mod_wsgi . 现在在我的烧瓶应用程序中,它位于/ var / www / html / truckman / wsgi文件夹中,我使用以下内容创建了truckman.wsgi文件:

activate_this = '/var/www/html/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import sys
sys.path.insert(0, '/var/www/html/truckman/wsgi/')

from app import app as application
import config
application.config.from_object(config.Dev)

另外,在/etc/httpd/conf/httpd.conf中我添加了:

<VirtualHost *>
    WSGIScriptAlias / /var/www/html/truckman/wsgi/truckman.wsgi
    <Directory /var/www/html/truckman/wsgi>
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

现在,在/ var / www / html / truckman / wsgi文件夹中,我创建了run.py文件,其中包含以下内容:

from app import app as application
import config
application.config.from_object(config.Dev)
if __name__ == "__main__":
    application.run(port=5001)

现在我用flask的开发服务器测试了我的应用程序;如果我执行“python run.py”,我的应用程序按预期工作 . 我可以浏览到localhost:5001,并显示应用程序的初始页面 .

然后我用mod_wsgi测试了我的应用程序:首先杀死run.py进程,然后重新启动httpd服务,之后浏览到localhost;但它返回:“500内部服务器错误” . 在/ etc / httpd / logs / error_log文件中,我发现以下错误消息:“ImportError:没有名为flask的模块” . 我的设置有什么问题?

1 回答

  • 0

    尝试在虚拟环境中添加python 2.7文件夹的路径 .

    sys.path.insert(1, '/path/to/virtualenv/lib/python2.7')
    

相关问题