Matplotlib 和 WSGI/mod_python 不适用于 Apache
Django 开发服务器上的一切都按预期运行。在 Apache 中,除非使用 matplotlib,否则 django 应用程序也可以工作。这是我得到的错误:
No module named multiarray.
Exception Type: ImportError
Exception Value: No module named multiarray
Exception Location: /usr/share/pyshared/numpy/core/numerictypes.py in <module>, line 81
Python Executable: /usr/bin/python
Python Version: 2.6.4
从 python shell 中,两个语句都有效: import numpy.core.multiarray 和 import multiarray 。有什么想法吗? 谢谢
当我查看 numpy 文件时,我发现了多数组模块,它的扩展名为“so”。我的猜测是 mod_python 没有读取这些文件。
Everything works as supposed to on the Django development server. In Apache, the django app also works except when matplotlib is used. Here's the error I get:
No module named multiarray.
Exception Type: ImportError
Exception Value: No module named multiarray
Exception Location: /usr/share/pyshared/numpy/core/numerictypes.py in <module>, line 81
Python Executable: /usr/bin/python
Python Version: 2.6.4
From the python shell, both statements work: import numpy.core.multiarray and import multiarray. Any ideas?
Thanks
As I'm looking over the numpy files, I found the multiarray module, which has an extension of 'so'. My guess, is that mod_python is not reading these files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题解决了。这就是我所做的。
首先,在我收到导入错误之前:
“没有名为 multiarray 的模块。”
我收到这样的错误:
“:无法创建 /some/dir/.matplotlib;考虑将 MPLCONFIGDIR 设置为 matplotlib 配置数据的可写目录”
通过将 pyshared 文件夹添加到 PythonPath 变量,此错误消失了,我得到了导入错误。
所以这是我修复它的方法:
从 PythonPath 变量中删除 pyshared 文件夹。
在导入 matplotlib 模块之前,添加这些行:
接下来,在导入 matplotlib.pyplot 或 pylab 之前,添加这些行:
这是记录的 此处。
就是这样!它现在正在为我工作 python2.5 。但我相信它也可以在 2.6 上运行。
Problem solved. Here's what I did.
First of all, before I was getting the import error:
"No module named multiarray."
I was getting an error like this:
": Failed to create /some/dir/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"
By adding the pyshared folder to the PythonPath variable, this error went away and I got the import error.
So here's how I fixed it:
Removed the pyshared folder from the PythonPath variable.
Before importing the matplotlib module, add these lines:
Next, before import matplotlib.pyplot or pylab, add these lines:
This is documented here.
That's is! It's working on python2.5 for me now. But I believe it'll work on 2.6 as well.
在 Win32 上,我通过从 py2.6.5 降级到 py2.5 解决了类似的问题(无法通过 ISAPI_WSGI (IIS) 加载 pyd 模块)。看起来这可能是一个被重新引入的 Python bug。例如,请参阅此讨论。
On Win32 I solved a similar problem (not being able to load pyd modules through ISAPI_WSGI (IIS)) by downgrading from py2.6.5 to py2.5. It seems like this might be a Python bug that has been re-introduced. See for example this discussion.