部署后在 django 中使用 scipy.stats.stats [英] Using scipy.stats.stats in django after deployment

查看:39
本文介绍了部署后在 django 中使用 scipy.stats.stats的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个严重依赖 scipy.stats.stats(scipy 版本 0.9.0)的包创建一个由 django 驱动的 (1.3) 接口,称为 ovl .在早期的开发阶段,使用 djangos 自己的开发服务器,这是没有问题的.使用apache debian/2.2.9和mod_wsgi 3.3部署后,出现严重问题.

I am in the process of creating an django-powered (1.3) interface to a package that relies heavily in scipy.stats.stats (scipy version 0.9.0), called ovl . During early development phases, using djangos own development-server, this was no problem. After deployment using apache debian/2.2.9 and mod_wsgi 3.3, this causes a serious problem.

无论我试图在浏览器中加载什么视图,它都会开始加载,并持续加载 5 分钟(直到超时),然后出现 500 页.仅导入 scipy 就可以工作,但是 不会 使 scipy.stats.stats 甚至 scipy.stats 可用.这并不奇怪;在 scipy 的 init.py 文档中,声明子包 stats 需要显式导入.但是,子包 cluster 也是如此,它在 django 中导入(从 web 在 django-shell 中)没有任何问题,并且确实出现在 dir(scipy),它在 ipython(0.10.2) 会话中没有,它只是没有出现,就像我预期的那样.

Whatever view I'm trying to load in the browser, it starts loading, and keeps doing that for a good 5 minutes (until time-out) and a 500 page appears. Just importing scipy works but, does not make scipy.stats.stats or even scipy.stats available. This is no surprise; in the documentation in scipy's init.py it is stated that the subpackage stats needs to be imported explicitly. However, the same is said about the subpackage cluster, which imports in django (from the web and in the django-shell) without any problem and indeed shows up in dir(scipy), which it doesn't in an ipython(0.10.2)-session, where it just doesn't show up, like I kinda expected.

在命令dir(scipy)上;它在普通的 ipython shell(564 个字符串,没有子包 cluster)中来自 web 时返回不同的结果(568 个字符串的列表,包括子包 cluster)和惊喜,令人惊讶的是,在 django shell 中.在 django shell 中,scipy 有 570 个属性,包括 clusterstats 包.

On the command dir(scipy); it returns different results when coming from the web (a list of 568 strings, including the subpackage cluster) in the normal ipython shell (564 strings, no subpackage cluster) and surprise, surprise, in the django shell. In the django shell scipy has 570 attributes, including both cluster and stats packages.

另一件事是,如果我继续导入 ovl-package,同时将 scipy.stats 导入保持在一定距离(不是在应用程序本身的一个文件中),有时我收到一个 ViewDoesNotExist 错误,指出视图模块中没有方法索引,而显然有一个.这让我想起了 这个.

Another thing is, if I keep importing the ovl-package, while keeping the scipy.stats imports at a bit of a distance (not in one of the files of the app itself), sometimes I get a ViewDoesNotExist error stating that there is no method index in the views module while there clearly is one. Which reminds me of this.

所以现在我正在考虑这些相当丑陋的解决方案:

So now I'm thinking of these rather ugly solutions:

  • 编辑 scipy 的 init 以导入 stats 包,使其正常"出现在 dir(scipy) 中,并且可以通过 scipy.stats 访问,我可以使用旧代码.
  • 获取 scipy 的 stat 子包并从中制作一个常规包(可能使用符号链接)

不过,我不太愿意应用这些解决方案.事实集群在 django 环境中出现在 scipy 中,这让我有点担心.我想这可能与从网络登录时成为 www-data 用户有关,但我不知道如何检查.

I'm reluctant in applying these solutions, however. The fact cluster shows up in scipy in a django environment worries me a bit. I thought maybe this has something to do with being www-data user when logging in from the web, but I don't know how to check for that.

有没有其他人遇到过这种情况?这部分?或者其他有用的想法?

Did anyone else encounter this? Parts of this? Or otherwise helpful thoughts?

哦,另一个 django 部署确实有效.

Oh and another django deployment does work.

推荐答案

mod_python 用于尝试在同一进程中使用多个 Python 解释器.mod_wsgi 可能也在做同样的事情.虽然这通常可以正常工作,但某些扩展模块不支持此功能.scipy.stats 可能正在导入这样的扩展模块.我们在 scipy 邮件列表上有关于 mod_python 下的 scipy.stats 的类似报告.查看 mod_wsgi 文档,看看您是否可以对其进行配置,使其不在同一进程中使用多个解释器,或者找到一种不同的部署策略,为应用程序的每个进程使用一个解释器.

mod_python used to try using multiple Python interpreters in the same process. mod_wsgi might be doing the same. While this frequently works okay, some extension modules do not support this. scipy.stats is probably importing such an extension module. We have had similar reports on the scipy mailing list concerning scipy.stats under mod_python. Check the mod_wsgi documentation to see if you can configure it such that it does not use multiple interpreters in the same process, or find a different deployment strategy that uses one interpreter per process for the app.

这篇关于部署后在 django 中使用 scipy.stats.stats的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆