[Python] Flask is installed but apache returning `ModuleNotFoundError: No module named 'flask'`

Discussão em 'Python' iniciado por Stack, Abril 14, 2025.

  1. Stack

    Stack Membro Participativo

    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

    Continue reading...

Compartilhe esta Página