Flask 已安装,但 apache 返回“ModuleNotFoundError:没有名为“flask”的模块”
我正在尝试在我的 ubuntu Apache2 安装上设置 wsgi 和 Flask。
我通过设置 Flask 应用程序将 Flask 安装到我的 python 安装中
python3.10 -m pip install flask
,在出现 500 服务器错误后,我检查 error.log 文件并找到 ModuleNotFoundError: No module named 'flask'
完整错误日志:
[Wed Feb 23 16:41:31.830897 2022] [mpm_event:notice] [pid 10674:tid 140023780329344] AH00489: Apache/2.4.48 (Ubuntu) mod_wsgi/4.7.1 Python/3.9 configured -- resuming normal operations
[Wed Feb 23 16:41:31.831180 2022] [core:notice] [pid 10674:tid 140023780329344] AH00094: Command line: '/usr/sbin/apache2'
[Wed Feb 23 16:41:33.291698 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] mod_wsgi (pid=10675): Failed to exec Python script file '/var/www/search/search.wsgi'.
[Wed Feb 23 16:41:33.291819 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] mod_wsgi (pid=10675): Exception occurred processing WSGI script '/var/www/search/search.wsgi'.
[Wed Feb 23 16:41:33.292358 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] Traceback (most recent call last):
[Wed Feb 23 16:41:33.292446 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] File "/var/www/search/search.wsgi", line 8, in <module>
[Wed Feb 23 16:41:33.292465 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] from search import app as application
[Wed Feb 23 16:41:33.292492 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] File "/var/www/search/search/__init__.py", line 3, in <module>
[Wed Feb 23 16:41:33.292505 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] from flask import Flask, render_template, request
[Wed Feb 23 16:41:33.292549 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] ModuleNotFoundError: No module named 'flask'
我有<代码>#! /usr/bin/python3.10 在我的 wsgi 文件和我的 __init__.py (flask 应用程序)文件中。
我的系统上只安装了一个 python 3.10(至少我指向的 python 3.10 的路径有它),但找不到它,这是怎么回事?
编辑2:
包括search.wsgi
:
#!/usr/bin/python.10
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/search/")
from search import app as application
但是再看一遍,尽管使用了3.10,但看起来我安装的包libapache2-mod-wsgi-py3
仍在使用3.9由于某种原因
I'm trying to setup wsgi and flask on my ubuntu Apache2 installation.
I installed flask to my python installation through
python3.10 -m pip install flask
I setup my flask app, and after a 500 server error I check the error.log file and find ModuleNotFoundError: No module named 'flask'
Full error log:
[Wed Feb 23 16:41:31.830897 2022] [mpm_event:notice] [pid 10674:tid 140023780329344] AH00489: Apache/2.4.48 (Ubuntu) mod_wsgi/4.7.1 Python/3.9 configured -- resuming normal operations
[Wed Feb 23 16:41:31.831180 2022] [core:notice] [pid 10674:tid 140023780329344] AH00094: Command line: '/usr/sbin/apache2'
[Wed Feb 23 16:41:33.291698 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] mod_wsgi (pid=10675): Failed to exec Python script file '/var/www/search/search.wsgi'.
[Wed Feb 23 16:41:33.291819 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] mod_wsgi (pid=10675): Exception occurred processing WSGI script '/var/www/search/search.wsgi'.
[Wed Feb 23 16:41:33.292358 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] Traceback (most recent call last):
[Wed Feb 23 16:41:33.292446 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] File "/var/www/search/search.wsgi", line 8, in <module>
[Wed Feb 23 16:41:33.292465 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] from search import app as application
[Wed Feb 23 16:41:33.292492 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] File "/var/www/search/search/__init__.py", line 3, in <module>
[Wed Feb 23 16:41:33.292505 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] from flask import Flask, render_template, request
[Wed Feb 23 16:41:33.292549 2022] [wsgi:error] [pid 10675:tid 140023760172608] [client 192.168.0.2:50401] ModuleNotFoundError: No module named 'flask'
I have #! /usr/bin/python3.10
in both my wsgi file and my __init__.py
(flask app) file.
I only have one installation of python 3.10 on my system (at least the path to python 3.10 I pointed to has it), and it isn't found, What is going on?
EDIT 2:
Including search.wsgi
:
#!/usr/bin/python.10
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/search/")
from search import app as application
However looking at it again, despite using 3.10, it looks like the package I installed libapache2-mod-wsgi-py3
is still using 3.9 for some reason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,python 版本运行的是 python3.9,而不是我安装的 python3.10。
我把flask安装到3.9了,还是不行。最后我最终使用了 -H 命令:
sudo -H python3 -m pip installflask
它起作用了
First of all the python version was running
python3
which pointed to python3.9 and not my python3.10 installation.I installed flask to 3.9 and it still didn't work. In the end I ended up having the use of
-H
command:sudo -H python3 -m pip install flask
And it worked