首页 > 解决方案 > 目标 WSGI 脚本无法作为 python 模块加载,并使用 python 2.7 而不是 venv 中的 python 版本编译

问题描述

Wsgi 无法使用 venv 中的 python 版本编译应用程序,而是始终使用 python 2.7 编译。这是我的文件,请帮忙

我正在尝试使用 Apache 2.4.6 和 mod-wsgi 部署烧瓶应用程序 centos 7。

目标 WSGI 脚本 '/home/nmapi/project/dir/app.wsgi' 无法加载,因为 Python 模块是错误

这是我的 app.wsgi

activate_this = '/home/nmapi/venv/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))

使用您的应用程序路径展开 Python 类路径

from werkzeug.wsgi import DispatcherMiddleware
import sys
import logging
print(sys.path)
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"home/nmapi/project/dir")

from run import *

我的虚拟主机配置是

WSGISocketPrefix /var/run/wsgi

            #ServerName sample.server.com 
            WSGIApplicationGroup %{GLOBAL}
            WSGIDaemonProcess score  threads=5 python-home=/home/nmapi:home/nmapi/deps/venv/lib/python3.5

            WSGIScriptAlias /test_wsgi 
            /home/nmapi/project/dir/datascience.wsgi
            <Directory /home/nmapi/project/dir/>
                    #WSGIProcessGroup score
                    #AllowOverride All
                    Require all granted
                    #Allow from all
            </Directory>
            Alias /static /home/nmapi/project/dir/static
            <Directory /home/nmapi/project/dir/static/>
                    WSGIProcessGroup score
                    #WSGIApplicationGroup %{GLOBAL}
                    #AllowOverride All
                    Require all granted
                    #Allow from all
            </Directory>
            ErrorLog logs/error.log
            #ErrorLog /tmp/error.log
            LogLevel debug
            #CustomLog /tmp/access.log combined
            CustomLog logs/access.log combined

标签: apacheflaskmod-wsgi

解决方案


推荐阅读