python2.7.6 numpy 1.8.1 is actually api 7, not compatible with scipy or matplotlib

Asked by Bruce Labitt

For python 2.7.6 numpy1.8.1 is api 7 and is no longer compatible with matplotlib, or scipy which are at a higher api 9. This effectively makes numpy useless for scientific users.

Ubuntu 14.04 LTS
Version 14.04.5

python-numpy:
  Installed: 1:1.8.1-1ubuntu1
  Candidate: 1:1.8.1-1ubuntu1
  Version table:
 *** 1:1.8.1-1ubuntu1 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
        100 /var/lib/dpkg/status

example:
$ ipython
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
Type "copyright", "credits" or "license" for more information.

IPython 1.2.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]: from scipy.io import savemat
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 9 but this version of numpy is 7
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-cb6e29c9ae78> in <module>()
----> 1 from scipy.io import savemat

/usr/lib/python2.7/dist-packages/scipy/io/__init__.py in <module>()
     83
     84 # matfile read and write
---> 85 from .matlab import loadmat, savemat, whosmat, byteordercodes
     86
     87 # netCDF file support

/usr/lib/python2.7/dist-packages/scipy/io/matlab/__init__.py in <module>()
     11
     12 # Matlab file read and write utilities
---> 13 from .mio import loadmat, savemat, whosmat
     14 from . import byteordercodes
     15

/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio.py in <module>()
     11
     12 from .miobase import get_matfile_version, docfiller
---> 13 from .mio4 import MatFile4Reader, MatFile4Writer
     14 from .mio5 import MatFile5Reader, MatFile5Writer
     15

/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio4.py in <module>()
      9 from numpy.compat import asbytes, asstr
     10
---> 11 import scipy.sparse
     12
     13 from scipy.lib.six import string_types

/usr/lib/python2.7/dist-packages/scipy/sparse/__init__.py in <module>()
    204
    205 from .base import *
--> 206 from .csr import *
    207 from .csc import *
    208 from .lil import *

/usr/lib/python2.7/dist-packages/scipy/sparse/csr.py in <module>()
     13 from scipy.lib.six.moves import xrange
     14
---> 15 from .sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
     16 get_csr_submatrix, csr_sample_values
     17 from .sputils import upcast, isintlike, IndexMixin, issequence

/usr/lib/python2.7/dist-packages/scipy/sparse/sparsetools/__init__.py in <module>()
      3 from __future__ import division, print_function, absolute_import
      4
----> 5 from .csr import *
      6 from .csc import *
      7 from .coo import *

/usr/lib/python2.7/dist-packages/scipy/sparse/sparsetools/csr.py in <module>()
     26 fp.close()
     27 return _mod
---> 28 _csr = swig_import_helper()
     29 del swig_import_helper
     30 else:

/usr/lib/python2.7/dist-packages/scipy/sparse/sparsetools/csr.py in swig_import_helper()
     22 if fp is not None:
     23 try:
---> 24 _mod = imp.load_module('_csr', fp, pathname, description)
     25 finally:
     26 fp.close()

ImportError: numpy.core.multiarray failed to import

In [2]: import numpy

In [3]: numpy.__version__
Out[3]: '1.7.1'

I get the same error if I import in plain python

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy.io as sio
RuntimeError: module compiled against API version 9 but this version of numpy is 7
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/scipy/io/__init__.py", line 85, in <module>
    from .matlab import loadmat, savemat, whosmat, byteordercodes
  File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/__init__.py", line 13, in <module>
    from .mio import loadmat, savemat, whosmat
  File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio.py", line 13, in <module>
    from .mio4 import MatFile4Reader, MatFile4Writer
  File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio4.py", line 11, in <module>
    import scipy.sparse
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/__init__.py", line 206, in <module>
    from .csr import *
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/csr.py", line 15, in <module>
    from .sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/sparsetools/__init__.py", line 5, in <module>
    from .csr import *
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/sparsetools/csr.py", line 28, in <module>
    _csr = swig_import_helper()
  File "/usr/lib/python2.7/dist-packages/scipy/sparse/sparsetools/csr.py", line 24, in swig_import_helper
    _mod = imp.load_module('_csr', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import
>>>

python3 is ok, python2.7 is not.
$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy.io
>>> from scipy.io import savemat
>>> import numpy
>>> numpy.__version__
'1.8.1'
>>>

scipy version for python2 and python3 are both '0.13.3'

Python 2.7.x Numpy / scipy / matplotlib all worked together seamlessly in 13.10

I develop simulations at work using numpy/scipy/matplotlib. The upgrade to 14.04 has broken all of my code. I did not expect this to happen on an LTS release. Sure, my fault, but surprising nonetheless

The git release number seems to match that on PyPI, as of today. Maybe they are both wrong?
/usr/lib/python2.7/dist-packages/numpy/version.py
full_version = '1.8.1'
git_revision = '62a7575fd82ddf028517780c01fecf7e0cca27aa'
release = True

From PyPI
numpy-1.8.1.tar.gz/numpy-1.8.1/numpy/version.py
full_version = '1.8.1'
git_revision = '62a7575fd82ddf028517780c01fecf7e0cca27aa'
release = True

Seems to be the same as the download from sourceforge. :(

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu python-numpy Edit question
Assignee:
No assignee Edit question
Solved by:
Bruce Labitt
Solved:
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

There are two sets of the packages:

python (2.x), python-numpy, python-matplotlib, python-scipy
and
python3, python3-numpy, python3-matplotlib, python3-scipy

that should correctly work together.

Are you using the Ubuntu-provided versions of scipy and mathlib, or did you try installing an updated version from somewhere else?

Or have you done something to your numpy installation - see your output:
In [3]: numpy.__version__
Out[3]: '1.7.1' <--- shouldn't that be 1.8.1 ?
Maybe you should try re-installing python-numpy.

Revision history for this message
Bruce Labitt (bdlabitt) said :
#2

May have messed things up with easy_install #@$! I found a numpy install in /usr/local/lib/python2.7/dist-packages which is 1.7.1
The numpy in /usr/lib/python2.7/dist-packages is 1.8.1

Can I try pip uninstall numpy-1.7.1 ?

This appears to be my local problem. My machine at work is ok. So as far as Ubuntu is concerned, my problem is solved.

Revision history for this message
Manfred Hampl (m-hampl) said :
#3

As far as I know, Ubuntu packages will not be installed in /usr/local/lib/python2.7/dist-packages but in /usr/lib/python2.7/dist-packages
What is there in /usr/local/lib/python2.7/dist-packages ? Is there anything else besides numpy? Maybe deleting the /usr/local/lib/python2.7/dist-packages/numpy* files/directories helps? Eventually you have to reinstall python-numpy afterwards to make sure that the Ubuntu version is correctly installed again.