Apache mod_wsgi ModuleNotFoundError:没有名为“select”的模块

Apache mod_wsgi ModuleNotFoundError: No module named 'select'

提问人:Victoria walker 提问时间:10/13/2023 最后编辑:Victoria walker 更新时间:10/13/2023 访问量:37

问:

我正在尝试为 Windows 10 上的 flask 应用程序(python 版本 3.11.1)设置 apache 2.4.57 服务器。当我运行httpd.exe并导航到相关的localhost页面时,我收到内部服务器错误。检查日志,我得到以下堆栈跟踪:

[Thu Oct 12 17:16:08.747857 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047] mod_wsgi (pid=19784): Failed to exec Python script file 'path/to/flask/and/wsgi/file/FlaskApp.wsgi'.
[Thu Oct 12 17:16:08.748944 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047] mod_wsgi (pid=19784): Exception occurred processing WSGI script 'C:/Users/Public/Documents/git/Apache/FlaskApp.wsgi'.
[Thu Oct 12 17:16:08.749916 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047] Traceback (most recent call last):\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]   File "C:/Users/Public/Documents/git/Apache/FlaskApp.wsgi", line 7, in <module>\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]     from f import app as application\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]   File "path/to/flask/and/wsgi/file\\f\\__init__.py", line 1, in <module>\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]     from f.main import app\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]   File "path/to/flask/and/wsgi/file\\f\\main.py", line 1, in <module>\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]     from flask import Flask\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]   File "path/to/flask/and/wsgi/file\\venv\\Lib\\site-packages\\flask\\__init__.py", line 5, in <module>\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]     from . import json as json\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]   File "path/to/flask/and/wsgi/file\\venv\\Lib\\site-packages\\flask\\json\\__init__.py", line 6, in <module>\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]     from ..globals import current_app\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]   File "path/to/flask/and/wsgi/file\\venv\\Lib\\site-packages\\flask\\globals.py", line 6, in <module>\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]     from werkzeug.local import LocalProxy\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]   File "path/to/flask/and/wsgi/file\\venv\\Lib\\site-packages\\werkzeug\\__init__.py", line 5, in <module>\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]     from .serving import run_simple as run_simple\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]   File "path/to/flask/and/wsgi/file\venv\\Lib\\site-packages\\werkzeug\\serving.py", line 19, in <module>\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]     import selectors\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]   File "path\to\user\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\selectors.py", line 12, in <module>\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047]     import select\r
[Thu Oct 12 17:16:08.751860 2023] [wsgi:error] [pid 19784:tid 876] [client 127.0.0.1:53047] ModuleNotFoundError: No module named 'select'\r

我认为这非常奇怪,因为 select 是一个标准库。

flask 应用程序是一个相当简单的 hello world 应用程序(因为我正在尝试设置一个基本示例):

main.py:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

然后将其导入到 .py 文件中:__init__

from f.main import app

我的 http.conf 文件指向以下 FlaskApp.wsgi:

import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, "path/to/flask/and/wsgi/file/f")   
sys.path.insert(0, "path/to/flask/and/wsgi/file")   

from f import app as application

httpd.conf 文件,我相信配置正确。LoadFile、LoadModule 和 WSGIPythonHome 都是从 的输出中复制的。httpd.conf 文件包括以下文件 myapp.conf:mod_wsgi-express module-config

<VirtualHost *:5000>
    servername flaskwill.com
    <Directory path/to/flask/and/wsgi/file/>
        Require all granted
    </Directory>
    <Directory path/to/flask/and/wsgi/file/f>
        Require all granted
    </Directory>
    WSGIScriptAlias / path/to/flask/and/wsgi/file/FlaskApp.wsgi   
</VirtualHost>

path/to/user 看起来像 C:/Users/John Smith/,无论出于何种原因,它最初(不是由我)配置为在其中有一个空格。我相信这个空间是我无法使用 mod_wsgi-express start-server 的原因(我在它创建的一个文件中遇到语法错误,导致一行包含此路径作为其中的一部分。它发现 selectors.py 的事实表明这不太可能是问题所在。

我尝试设置一个 virtualenv 而不是基本的 venv,它没有改变输出。Flask 本身运行良好,没有 Flask 时,apache 服务器运行良好。例如,如果我完全在 FlaskApp.wsgi 中定位应用程序,并且不调用 flask,我没有任何问题。

我真的不知道我还能尝试什么。我已经在谷歌上广泛搜索了这个问题,唯一接近的结果是“运行 pip install select”,由于显而易见的原因,它不起作用。

python Apache flask mod-wsgi

评论


答: 暂无答案