gpt4 book ai didi

python - Flask 和 Apache2 : No module named app

转载 作者:太空宇宙 更新时间:2023-11-04 03:21:23 28 4
gpt4 key购买 nike

我正在尝试通过 Apache2 部署 Flask 应用程序,但出现了 No module named app 错误。我也在使用 virtualenv

planer(Flask 应用)

(venv)jdoe@jdoe-virtual-machine:/var/www/planer$ la
app.py forms.py .git helpers.py __init__.py main.pyc models.pyc README.md setup.cfg templates views.py
app.pyc forms.pyc .gitignore helpers.pyc main.py models.py planer.wsgi requirements.txt static venv views.pyc

planer.conf

<VirtualHost *:80>
ServerName planer.dev
ServerAdmin admin@mywebsite.com
WSGIScriptAlias / /var/www/planer/planer.wsgi
<Directory /var/www/planer/planer/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/planer/static
<Directory /var/www/planer/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

planer.wsgi

import sys, os
sys.path.insert (0,'/var/www/planer')

sys.path = [
'/var/www/planer/venv/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
]

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

import app as application

错误

[Wed Jan 06 09:45:29.781102 2016] [:error] [pid 20727] [client 127.0.0.1:42448] mod_wsgi (pid=20727): Target WSGI script '/var/www/planer/planer.wsgi' cannot be loaded as Python module.
[Wed Jan 06 09:45:29.781137 2016] [:error] [pid 20727] [client 127.0.0.1:42448] mod_wsgi (pid=20727): Exception occurred processing WSGI script '/var/www/planer/planer.wsgi'.
[Wed Jan 06 09:45:29.781208 2016] [:error] [pid 20727] [client 127.0.0.1:42448] Traceback (most recent call last):
[Wed Jan 06 09:45:29.781235 2016] [:error] [pid 20727] [client 127.0.0.1:42448] File "/var/www/planer/planer.wsgi", line 12, in <module>
[Wed Jan 06 09:45:29.781302 2016] [:error] [pid 20727] [client 127.0.0.1:42448] import app as application
[Wed Jan 06 09:45:29.781327 2016] [:error] [pid 20727] [client 127.0.0.1:42448] ImportError: No module named app

最佳答案

确保 .wsgi 文件是可执行的:

sudo chmod a+x planer.wsgi

并尝试用这个加载它:

python /absolute/path/to/planer.wsgi

关于python - Flask 和 Apache2 : No module named app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34629035/

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