使用Apache导入Flask时出现语法错误

2024-05-05 20:15:02 发布

您现在位置:Python中文网/ 问答频道 /正文

无法让我的Flask/Apache应用程序正常工作。我似乎能够在api.wsgi文件中很好地导入我的应用程序。但是当我的api.py(flask)应用程序实际被读取时,我遇到了以下错误:

enter image description here

这看起来像是在运行错误版本的Python时出现的错误。但是您可以从目录中看到它使用的是Python3.7。所以注释语法应该很好

然而,我确实注意到了这一行: enter image description here

这是否意味着它实际上正在使用Python 2.7?如果是这样,那不是问题的根源吗? 这是我的配置:

<VirtualHost *:1024>
     WSGIDaemonProcess flask_api python-path=/var/www/html/flask_api:/var/www/html/flask_api/flask_env/lib/python3.7/site-packages
     # Add machine's IP address (use ifconfig command)
     ServerName 3.23.72.183
     # DocumentRoot /home/ec2-user/flask_api/
     # Give an alias to to start your website url with
     WSGIScriptAlias /api /var/www/html/flask_api/api.wsgi
     <Directory /var/www/html/flask_api>
            WSGIProcessGroup flask_api
            WSGIApplicationGroup %{GLOBAL}
                # set permissions as per apache2.conf file
            Options +Indexes +FollowSymLinks
            AllowOverride All
            Require all granted
     </Directory>
     LogLevel warn
</VirtualHost>

我用的是venv。如何确保Apache使用的是python 3.7?在全球范围内,我安装了Python2.7和Python3