如何解决在 apache/wsgi 下运行 python/poetry flask 应用程序时遇到问题
我用诗写了一个烧瓶应用程序,想在 apache 和 wsgi 的控制下运行它。我花了几个小时搜索文档和试验,我学到了很多,但仍然没有弄清楚。这是一连串的打击:
当我直接从诗歌中的命令行运行该应用程序时,它可以工作:
python3 ./otproject/otpflask/src/run.py
* Serving Flask app 'teacher' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production Wsgi server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 141-706-196
^Crpsalas@otproject:~/mydev/development$
根据诗歌,我的venv在这里:
$ poetry env info
VirtualEnv
Python: 3.8.10
Implementation: cpython
Path: /home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8
Valid: True
System
Platform: linux
OS: posix
Python: /usr
然后我配置我的apache mod_wsgi如下
<VirtualHost *:80>
WsgiDaemonProcess test python-home=/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8
WsgiProcessGroup test
WsgiApplicationGroup %{GLOBAL}
WsgiScriptAlias /test /var/www/test/test.wsgi
<Directory /var/www/test/src/>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
wsgi python 脚本 test.wsgi 如下所示:
#!/usr/bin/env python
from otproject.otpflask.teacher import app as application
但是当我重新启动 apache 服务时,它严重失败了:
Fatal Python error: init_fs_encoding: Failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f99756e4c40 (most recent call first):
<no Python frame>
[Sun Jul 25 20:35:24.503068 2021] [wsgi:warn] [pid 154900:tid 140297076886592] (13)Permission denied: mod_wsgi (pid=154900): Unable to stat Python home /home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Python path configuration:
PYTHONHOME = '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8'
PYTHONPATH = (not set)
program name = 'python3'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/usr/bin/python3'
sys.base_prefix = '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8'
sys.base_exec_prefix = '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8'
sys.executable = '/usr/bin/python3'
sys.prefix = '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8'
sys.exec_prefix = '/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8'
sys.path = [
'/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8/lib/python38.zip','/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8/lib/python3.8','/home/rpsalas/.cache/pypoetry/virtualenvs/otproject-Yy_WWjvb-py3.8/lib/python3.8/lib-dynload',]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。