cafe_
cafe_

Reputation: 213

Django, GAE, numpy: cannot import name multiarray

I can't get numpy working with Django (django-nonrel) and Google App Engine. Here's the project structure:

gae/
  virtualenv_directory/
  project/
    app/
      views.py
      algorithm.py
      ...
    lib/
      nltk/
      numpy/
      ...
    nltk_data/
    settings.py

All third-party libraries are installed in lib/ directory using command: "pip install -t . package". Also, settings.py contains the line:

sys.path.append(os.path.join(PROJECT_PATH, 'lib'))

In views.py I call a function from algorithm.py, which uses nltk. However, when calling it as a user (on development server) I get the following error:

Exception Type: ImportError
Exception Value: cannot import name multiarray
Exception Location: /home/me/gae/project/lib/numpy/core/init.py in , line 6
Python Executable: /home/me/gae/virtualenv_directory/bin/python
Python Version: 2.7.3

Traceback ends with line:

File "/home/me/gae/project/lib/numpy/core/init.py" in
6. from . import multiarray

Local vars:

file None
absolute_import None
package None
path None
name None
version None
doc None
print_function None

Ultimate answer to relative python imports says that:

Relative imports use a module's name attribute to determine that module's position in the package hierarchy. If the module's name does not contain any package information (e.g. it is set to 'main') then relative imports are resolved as if the module were a top level module, regardless of where the module is actually located on the file system.

So it seems that the error is caused by name equal to 'None'. But what is the reason for it?

In ./manage.py shell I can import numpy.core.multiarray or call the function from algorithm.py without any errors.

I've also tried to use GAE numpy, adding the following lines to app.yaml:

- name: numpy
  version: latest

But the result was another import error, that is:

Exception Value: cannot import name scimath
Exception Location: /home/me/gae/virtualenv_directory/local/lib/python2.7/site-packages/numpy/lib/init.py in , line 17
Python Executable: /home/me/gae/virtualenv_directory/bin/python

/home/me/gae/virtualenv_directory/local/lib/python2.7/site-packages/numpy/lib/init.py in
17. from . import scimath as emath

Once again, all local vars mentioned above are equal to 'None'.

Any suggestions how to fix this?

Upvotes: 0

Views: 1978

Answers (1)

Houman
Houman

Reputation: 66320

I had the same problem on Mac. You can't install numpy 1.6.1 on Mac despite using

CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install numpy==1.6.1

And I couldn't use the latest numpy due dependencies on multiarray namespace. Besides currently GAE only supports only up to numpy===1.6.1 hence it makes sense to have any higher version installed.

The solution was for me to install 1.6.2, which I could install on Mac and has still the needed multiarray. Now I can import numpy in GAE and it works.

Upvotes: 2

Related Questions