5

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.

Luiz C.
  • 746
  • 11
  • 22
  • What happens if you do "from numpy.core.multiarray import typeinfo, ndarray, array, empty, dtype" from the python shell? – Mark Apr 01 '10 at 17:33
  • that works fine. no error messages. – Luiz C. Apr 01 '10 at 17:36
  • I seem to have a similar problem. I'm running py2.6, cherrypy, IIS, isapi_wsgi. Matplotlib works fine from the Python shell. Trying to load pyd modules (e.g. matplotlib._path) fails when called by IIS. I've checked os.environ and sys.path. – e1i45 Apr 10 '10 at 03:28
  • e1i45: what version of matplotlib are you running? I have 1.3.0 on Ubuntu. I have it successfully running on windows xp with matplotlib version 1.4.0rc1. – Luiz C. Apr 10 '10 at 03:30
  • I'm running matplotlib Version 0.99.1 – e1i45 Apr 10 '10 at 04:39

2 Answers2

9

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:

import os
os.environ['HOME']='/some/writable/dir'

Next, before import matplotlib.pyplot or pylab, add these lines:

import matplotlib
matplotlib.use('Agg') 
# 'Agg' or whatever your backend is.

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.

Luiz C.
  • 746
  • 11
  • 22
1

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.

e1i45
  • 1,519
  • 1
  • 14
  • 20
  • I think you're right. I have everything working on a windows machine with python 2.5. However, Ubuntu comes with python 2.6 and makes it very very hard to downgrade to python 2.5. On top of that, you can't install mod_python if your current python version is 2.5. – Luiz C. Apr 13 '10 at 16:58