Python error, sci-python -- help

I wanna make next simple program work :



from numpy import arange,array,ones,random,linalg
from pylab import plot,show

xi = arange(0,9)
A = array( xi, ones(9)])
# linearly generated sequence
y = [19, 20, 20.5, 21.5, 22, 23, 23, 25.5, 24]
w = linalg.lstsq(A.T,y)[0] # obtaining the parameters

# plotting the line
line = w[0]*xi+w[1] # regression line
plot(xi,line,'r-',xi,y,'o')
show()

and like you can see I have installed what i need:


 # rpm -q python
python-2.7.3-3.6.1.x86_64

# rpm -q python-numpy
python-numpy-1.6.2-3.1.2.x86_64


And when I try to import numpy, pylab
I get next error:


>>> import numpy
>>> import pylab
RuntimeError: module compiled against API version 7 but this version of numpy is 6
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/usr/lib64/python2.7/site-packages/matplotlib/pylab.py", line 222, in <module>
    from matplotlib import mpl  # pulls in most modules
  File "/usr/lib64/python2.7/site-packages/matplotlib/mpl.py", line 1, in <module>
    from matplotlib import artist
  File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 7, in <module>
    from transforms import Bbox, IdentityTransform, TransformedBbox, \
  File "/usr/lib64/python2.7/site-packages/matplotlib/transforms.py", line 35, in <module>
    from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: numpy.core.multiarray failed to import

:sarcastic:???

Why didn’t you post this in the Development > Programming and Scipting forum?
My guess would be that the chance that people doing programming (and maybe even programming in Pyton) woould read this would be muchy better.

When, as an afterthought, you thiink it in fact would have been better placed there, please ask, I can mve it. (And please do not come to the conclusion that making a double post is a good idea, because it is not).

Well, your pylab and numpy don’t fit together. I’d guess your pylab would need python-numpy 1.7.

Where do you have pylab from?

You can find 1.7 packages of python-numpy here: openSUSE Software
(click on “Show unstable packages” and use either devel:languages:python or science repo, I’d suggest)

On 2013-05-08, Aleksandar30 <Aleksandar30@no-mx.forums.opensuse.org> wrote:
> And when I try to import numpy, pylab
> I get next error:
>
>
> Code:
> --------------------
>
> >>> import numpy
> >>> import pylab
> RuntimeError: module compiled against API version 7 but this version of numpy is 6
> Traceback (most recent call last):
> File “<stdin>”, line 1, in <module>
> File “/usr/lib64/python2.7/site-packages/pylab.py”, line 1, in <module>
> from matplotlib.pylab import *
> File “/usr/lib64/python2.7/site-packages/matplotlib/pylab.py”, line 222, in <module>
> from matplotlib import mpl # pulls in most modules
> File “/usr/lib64/python2.7/site-packages/matplotlib/mpl.py”, line 1, in <module>
> from matplotlib import artist
> File “/usr/lib64/python2.7/site-packages/matplotlib/artist.py”, line 7, in <module>
> from transforms import Bbox, IdentityTransform, TransformedBbox,
> File “/usr/lib64/python2.7/site-packages/matplotlib/transforms.py”, line 35, in <module>
> from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
> ImportError: numpy.core.multiarray failed to import
>
> --------------------
>

There are no problems with your python code running with numpy/scipy/matplotlib installed on openSUSE 12.3 - please tell
us which version of openSUSE you are using.

However I can already see the likely cause: your numpy version (1.6) is the wrong one to work with the your version of
matplotlib - it’s nothing to do with scipy. You shouldn’t have installed numpy using `rpm’ but using:


zypper ar -f http://download.opensuse.org/repositories/devel:/languages:/python/openSUSE_12.3/ "python"
zypper in ipython python-ipdb
zypper in python-numpy python-scipy python-matplotlib python-matplotlib-tk

Then once again try your code and it should work. You an be able to confirm the correct versioning thus:


sh-4.2$ python
Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> import matplotlib
>>> numpy.__version__
'1.7.1'
>>> scipy.__version__
'0.12.0'
>>> matplotlib.__version__
'1.2.0'
>>>
>>> exit()
sh-4.2$

HTH

On 2013-05-08, hcvv <hcvv@no-mx.forums.opensuse.org> wrote:
> Why didn’t you post this in the Development > Programming and Scipting
> forum?
> My guess would be that the chance that people doing programming (and
> maybe even programming in Pyton) woould read this would be muchy better.
>
> When, as an afterthought, you thiink it in fact would have been better
> placed there, please ask, I can mve it. (And please do not come to the
> conclusion that making a double post is a good idea, because it is not).

I agree with hcvv that the post would better have been placed in Development, but I expect the issue to be resolved
after executing the zypper commands I’ve included above. If it still doesn’t work, then perhaps the post should be
moved.

Aleksandar30 wrote:

>
> I wanna make next simple program work :
>
>
> Code:
> --------------------
>
>
> from numpy import arange,array,ones,random,linalg
> from pylab import plot,show
>
> xi = arange(0,9)
> A = array( xi, ones(9)])
> # linearly generated sequence
> y = [19, 20, 20.5, 21.5, 22, 23, 23, 25.5, 24]
> w = linalg.lstsq(A.T,y)[0] # obtaining the parameters
>
> # plotting the line
> line = w[0]*xi+w[1] # regression line
> plot(xi,line,‘r-’,xi,y,‘o’)
> show()
>
> --------------------
>
>
> and like you can see I have installed what i need:
>
>
> Code:
> --------------------
>
> # rpm -q python
> python-2.7.3-3.6.1.x86_64
>
> # rpm -q python-numpy
> python-numpy-1.6.2-3.1.2.x86_64
>
>
> --------------------
>
>
> And when I try to import numpy, pylab
> I get next error:
>
>
> Code:
> --------------------
>
> >>> import numpy
> >>> import pylab
> RuntimeError: module compiled against API version 7 but this version of
> numpy is 6 Traceback (most recent call last):
> File “<stdin>”, line 1, in <module>
> File “/usr/lib64/python2.7/site-packages/pylab.py”, line 1, in <module>
> from matplotlib.pylab import *
> File “/usr/lib64/python2.7/site-packages/matplotlib/pylab.py”, line 222,
> in <module>
> from matplotlib import mpl # pulls in most modules
> File “/usr/lib64/python2.7/site-packages/matplotlib/mpl.py”, line 1, in
> <module> from matplotlib import artist
> File “/usr/lib64/python2.7/site-packages/matplotlib/artist.py”, line 7,
> in <module> from transforms import Bbox, IdentityTransform,
> TransformedBbox, \ File
> “/usr/lib64/python2.7/site-packages/matplotlib/transforms.py”, line 35,
> in <module> from matplotlib._path import (affine_transform,
> count_bboxes_overlapping_bbox, ImportError: numpy.core.multiarray failed
> to import
>
> --------------------
>
> :sarcastic:???
>
>
I’m running openSuse 12.3 with KDE and all standard updates (including
packman)

Code:

graham@linux:~> rpm -q python python-numpy
python-2.7.3-10.1.1.x86_64
python-numpy-1.6.2-10.1.1.x86_64
graham@linux:~> python

The code runs OK here with no error messages.
I note my versions are later than yours.

I’m quite new on forums and I wasn’t really sure where to put this question.
Programs I make are really calculus oriented and I wasn’t sure should I put this question in development section cause I see myself as just a user and not developer.

I tried to solve problem on the way mentioned below and it didn’t work.:frowning:

So could you please move this post in Development > Programming and Scipting forum.

Sorry I wont make this mistake again.

Big thanks!

Well, what exactly did you try? And how exactly didn’t it work? (error messages, f.e.)
We can only help you further if you tell us what’s wrong.
We don’t see what you see, we don’t think what you think; we are miles away…:wink:

SOLVED
This is solution:


zypper install python-numpy-1.7.1-64.1.x86_64

The problem was that system didn’t wanted to upgrade it with commands given up there(I’ve tried them before posting) and I needed to enter exact versio.:slight_smile:


>>> numpy.__version__
'1.6.2'
>>> scipy.__version__
'0.12.0'
>>> matplotlib.__version__
'1.2.0'

Big thanks to all !!! rotfl!

P.S.
I run opensuse 12.2 :wink:

It was showing same error as before cause it didn’t upgrade.

python-numpy-1.6.2 -> python-numpy-1.7.1

And I was getting info that there is no newer version than 1.6.2!


zypper in python-numpy python-scipy python-matplotlib python-matplotlib-tk

or:


zypper install python-numpy

I would get response that I have newest version and that it is "python-numpy-1.6.2 " and that upgrade isn’t available.
I don’t understand why :\

But when I specify version which I want 1.7.1 it just worked and download it rotfl!


zypper install python-numpy-1.7.1-64.1.x86_64

Thanks for help!!!lol!

OK, this seems to be solved to the joy of theOP.
This will nevertheless be moved to Programming and Scripting to have it there for future reference.

This is temporary CLOSED.

Moved from Applicaitons and open again.