简体   繁体   English

在 Windows 上使用 apache mod_wsgi 运行 Flask 应用程序时导入冲突

[英]Import conflict when running flask app with apache mod_wsgi on windows

I am permit you to ask you about a problem that I have with hosting flask application with your portage of mod_wsgi on windows我允许你问你一个问题,我在 Windows 上使用你的 mod_wsgi 移植托管烧瓶应用程序

I have two flask application and only one can be alive a the same times due to conflict in import我有两个烧瓶应用程序,由于导入冲突,只有一个可以同时存活

ie : If a request application 1 I have a response Then if I request application 2 I have internal server error with error in log ... Then if I restart apache and I request application 2 I have a response but if I request application 1 I have the same internal server error If I comments some import like numpy both application can be alive at the same time即:如果请求应用程序 1 我有响应然后如果我请求应用程序 2 我有内部服务器错误,日志中有错误...然后如果我重新启动 apache 并请求应用程序 2 我有响应但如果我请求应用程序 1 我有相同的内部服务器错误如果我评论一些像 numpy 这样的导入,两个应用程序可以同时处于活动状态

Any help would be appreciated if you have any idea or link or answer to about this problem?如果您对此问题有任何想法或链接或答案,将不胜感激?

My installation is describe below我的安装描述如下

Thanks by advance for tour times and your works提前感谢您的巡演时间和您的作品

Alexandre亚历山大

LOG of the error错误日志
mod_wsgi (pid=4936): Failed to exec Python script file 'D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi'. mod_wsgi (pid=4936):无法执行 Python 脚本文件“D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi”。
mod_wsgi (pid=4936): Exception occurred processing WSGI script 'D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi'. mod_wsgi (pid=4936):处理 WSGI 脚本“D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi”时发生异常。
Traceback (most recent call last):回溯(最近一次调用最后一次):
File "D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi", line 3, in文件“D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi”,第 3 行,在
from api_test_2 import app as application从 api_test_2 导入应用程序作为应用程序
File "D:/exec/wsgi_api/api_test_2\\api_test_2.py", line 2, in文件“D:/exec/wsgi_api/api_test_2\\api_test_2.py”,第 2 行,在
import numpy导入 numpy
File "c:\\python\\python36\\lib\\site-packages\\numpy\\__init__.py", line 142, in文件“c:\\python\\python36\\lib\\site-packages\\numpy\\__init__.py”,第 142 行,在
from .从 。 import core进口核心
File "c:\\python\\python36\\lib\\site-packages\\numpy\\core\\__init__.py", line 16, in文件“c:\\python\\python36\\lib\\site-packages\\numpy\\core\\__init__.py”,第 16 行,在
from .从 。 import multiarray导入多阵列
File "c:\\python\\python36\\lib\\site-packages\\numpy\\core\\multiarray.py", line 12, in文件“c:\\python\\python36\\lib\\site-packages\\numpy\\core\\multiarray.py”,第 12 行,在
from .从 。 import overrides导入覆盖
File "c:\\python\\python36\\lib\\site-packages\\numpy\\core\\overrides.py", line 46, in文件“c:\\python\\python36\\lib\\site-packages\\numpy\\core\\overrides.py”,第 46 行,在
""") """)
RuntimeError: implement_array_function method already has a docstring运行时错误:implement_array_function 方法已经有一个文档字符串

#---------------------------------
# file : D:/exec/wsgi_api/api_test_1/api_test_1.py    
#---------------------------------
from flask import Flask, jsonify,render_template, request, make_response
import numpy
app = Flask(__name__)
@app.route('/')
def home():
    resp = make_response("hello from 1", 200)
    resp.headers['Content-Type'] = 'charset=utf-8'
    return resp
#---------------------------------        

#---------------------------------
# file : D:/exec/wsgi_api/api_test_2/api_test_2.py    
#---------------------------------
from flask import Flask, jsonify,render_template, request, make_response
import numpy
app = Flask(__name__)    
@app.route('/')
def home():
    resp = make_response("hello from 2", 200)
    resp.headers['Content-Type'] = 'charset=utf-8'
    return resp
if __name__ == '__main__':
    app.run(host='127.0.0.1', port=36000)
#---------------------------------

I have this two wsgi file in appache httpdocs我在 appache httpdocs 中有这两个 wsgi 文件

#---------------------------------
# file : D:/exec/Apache24/htdocs/wsgi/api_test_1.wsgi
#---------------------------------
import sys 
sys.path.append('D:/exec/wsgi_api/api_test_1/') 
from api_test_1 import app as application
#---------------------------------


#---------------------------------
# file : D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi
#---------------------------------
import sys 
sys.path.append('D:/exec/wsgi_api/api_test_1/') 
from api_test_1 import app as application
#---------------------------------


#---------------------------------
In D:/exec/Apache24/conf/httpd.conf i add the line
#---------------------------------
WSGIScriptAlias /api_test_1 "D:/exec/Apache24/htdocs/wsgi/api_test_1.wsgi"
WSGIScriptAlias /api_test_2 "D:/exec/Apache24/htdocs/wsgi/api_test_2.wsgi"
#---------------------------------

I had a similar issue in a project.我在一个项目中遇到了类似的问题。 In my case, I had to add WSGIApplicationGroup %{GLOBAL} inside the .conf file of my site.就我而言,我必须在我网站的.conf文件中添加WSGIApplicationGroup %{GLOBAL}

This is the documentation where I found the information:这是我找到信息的文档:
https://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#sub-interpreter-being-used https://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#sub-interpreter-being-used

I had a discussion on the mod_wsgi mailing list and I had the same response The explanation is numpy doesn't work in Python sub interpreters as the C extension modules are not implement properly to allow that, thus for mod_wsgi you can only use numpy in the main interpreter context, forced by the 'WSGIApplicationGroup %{GLOBAL}' directive我在 mod_wsgi 邮件列表上进行了讨论,我得到了相同的回复 解释是 numpy 在 Python 子解释器中不起作用,因为 C 扩展模块没有正确实现以允许这样做,因此对于 mod_wsgi,您只能在主解释器上下文,由 'WSGIApplicationGroup %{GLOBAL}' 指令强制

This is linked with the subject https://github.com/numpy/numpy/issues/3961这与主题https://github.com/numpy/numpy/issues/3961相关联

尝试将其放入您的 WSGI 配置文件中:

single-interpreter = true

This works for me这对我有用

i add WSGIApplicationGroup %{GLOBAL} in apache config file which is available in site-enabled folder.我在启用站点的文件夹中可用的 apache 配置文件中添加 WSGIApplicationGroup %{GLOBAL}。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM