Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get `No module named _multiarray_umath` when using matplotlib

When I run my tests in CI, I get the following error:

ImportError while importing test module '/home/tests/test_process.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
...
.tox/py27/lib/python2.7/site-packages/matplotlib/pyplot.py:31: in <module>
    import matplotlib.colorbar
.tox/py27/lib/python2.7/site-packages/matplotlib/colorbar.py:36: in <module>
    import matplotlib.contour as contour
.tox/py27/lib/python2.7/site-packages/matplotlib/contour.py:14: in <module>
    import matplotlib._contour as _contour
E   ImportError: numpy.core.multiarray failed to import
----- Captured stderr -----
ImportError: No module named _multiarray_umath

What's going on here? I haven't made any changes to my code, but all the sudden my build started failing.

like image 1000
user60561 Avatar asked Jan 11 '19 20:01

user60561


2 Answers

Solution

Install numpy using pip seperately, before installing your sdist.

For tox, add numpy directly to your deps array.

Why did this happen?

Numpy recently published numpy-1.16.0rc2 to pypy, which is what (in conjunction with a bug/oversight in easy_install) broke your build:

pip knows not to install RCs by default, but easy_install (which matplotlib uses to do their builds) does not. If you were to do sdist with a whole bunch of -vvvvvvs, you'd see something like this:

gcc ... -I/tmp/pip-install-Eh8d9d/matplotlib/.eggs/numpy-1.16.0rc2-py2.7-linux-x86_64.egg/numpy/core/include ... -o build/temp.linux-x86_64-2.7/src/_contour.o

In particular, note that matplotlib is being built against numpy-1.16.0rc2-py2.7. But then in another place you might see something like

Successfully installed ... numpy-1.15.4 ...

So then when you try and run your program, matplotlib will try to access modules that don't exist in the non-RC version of numpy, and fail.

If you already have numpy installed, easy_install won't try and fetch its own version, and will instead use the (correct) existing version.

See also

  • http://numpy-discussion.10968.n7.nabble.com/Issue-with-setup-requires-and-1-16-release-candidates-td46600.html
like image 116
user60561 Avatar answered Nov 14 '22 22:11

user60561


The solution is that you need to upgrade numpy. If you are using pip

pip install numpy --upgrade

Hope it helps.

like image 24
Abhinav Sagar Avatar answered Nov 14 '22 21:11

Abhinav Sagar