gpt4 book ai didi

python - Flask、mod_wsgi 和 Apache : ImportError

转载 作者:太空狗 更新时间:2023-10-29 20:42:33 24 4
gpt4 key购买 nike

我在我的错误日志中得到了这个:

ImportError: No module named flask

它看起来和 Django + mod_wsgi + apache: ImportError at / No module named djproj.urls 中的一模一样,但我尝试了该解决方案,但它似乎不起作用...我已将应用程序主文件夹和父文件夹正确插入到系统路径中,但此错误仍然出现。

导航到我的页面仍然会显示第 500 页。

更多信息:我正在使用 Amazon EC2免费层,以 httpd 的形式使用 Apache。一切都已正确安装,我很确定...

这是我的东西(应用名称 badassery 和应用主文件夹名称 hatemail - 我经常改变主意):

错误日志

[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] mod_wsgi (pid=28143): Target WSGI script '/home/ec2-user/hatemail/badassery.wsgi' cannot be loaded as Python module.
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] mod_wsgi (pid=28143): Exception occurred processing WSGI script '/home/ec2-user/hatemail/badassery.wsgi'.
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] Traceback (most recent call last):
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] File "/home/ec2-user/hatemail/badassery.wsgi", line 6, in <module>
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] from badassery import app as application
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] File "/home/ec2-user/hatemail/badassery.py", line 6, in <module>
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] from flask import Flask, request, session, url_for, redirect, render_template, abort, g, flash, _app_ctx_stack
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] ImportError: No module named flask
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] mod_wsgi (pid=28143): Target WSGI script '/home/ec2-user/hatemail/badassery.wsgi' cannot be loaded as Python module.
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] mod_wsgi (pid=28143): Exception occurred processing WSGI script '/home/ec2-user/hatemail/badassery.wsgi'.
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] Traceback (most recent call last):
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] File "/home/ec2-user/hatemail/badassery.wsgi", line 6, in <module>
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] from badassery import app as application
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] File "/home/ec2-user/hatemail/badassery.py", line 6, in <module>
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] from flask import Flask, request, session, url_for, redirect, render_template, abort, g, flash, _app_ctx_stack
[Sun Nov 11 07:14:45 2012] [error] [client 18.189.71.148] ImportError: No module named flask

坏蛋.wsgi

import sys

sys.path.insert(0,'/home/ec2-user/hatemail')
sys.path.insert(1,'/home/ec2-user')

from badassery import app as application

添加到 httpd.conf 文件

WSGISocketPrefix /var/run/wsgi

<VirtualHost *:80>
ServerName 54.243.61.41
DocumentRoot "/home/ec2-user/hatemail"

WSGIDaemonProcess badassery user=apache group=apache processes=1 threads=5
WSGIScriptAlias / /home/ec2-user/hatemail/badassery.wsgi
WSGIScriptReloading On

<Directory /home/ec2-user/hatemail>
WSGIProcessGroup badassery
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

目录结构

~
hatemail
badassery.py
badassery.wsgi
Procfile
README
requirements.txt
schema.sql
static/
templates/
venv/bin/activate

是的,我正在执行“if name == 'main': app.run()”。

我该如何解决这个问题?

最佳答案

如果你正在部署一个 virtualenv,你必须确保首先激活它。您应该像这样更新您的 wsgi 文件(更新值以匹配您的环境):

activate_this = '/path/to/virtualenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this)

import sys
sys.path.insert(0, '/path/to/flask/appname')
sys.path.insert(0,'/home/ec2-user/hatemail')
sys.path.insert(1,'/home/ec2-user')

from badassery import app as application

如果你没有部署 virtualenv,你可能只需要确保你的系统上安装了 Flask。如果您已经安装了 setuptools,您可以:

easy_install flask

关于python - Flask、mod_wsgi 和 Apache : ImportError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13329354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com