SciPy and NumPy on Mac OS 10.6.8 - python

I have installed Python 2.7.2 on my Mac, and it's working fine. I downloaded the binary for SciPy (http://sourceforge.net/projects/scipy/files/scipy/0.9.0/scipy-0.9.0-py2.7-python.org-macosx10.6.dmg) and NumPy (http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/numpy-1.6.1-py2.7-python.org-macosx10.6.dmg) respectively, and installed them.
However, when I tried the following, error occurred:
>>> import numpy
>>> print numpy._version_
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
print numpy._version_
AttributeError: 'module' object has no attribute '_version_'
However, this works fine:
>>> numpy.version.version
'1.6.1'
Since I am new to Python, I just followed on the instructions here. I wonder what may cause the error above? Thanks.

What you are looking for is numpy.__version__ with two underscores before and after the word version. By my inderstanding, that is the convention for private (or semi-private) variables in python.

Related

Using signal processing library in scipy

I want to use the signal processing library under Scipy. But running the following example code given in Scipy webpage has given me an error. I have rechecked my Scipy installation and it is the latest.
The example code I ran is as follows
from scipy import signal
import numpy as nu
b=nu.array([0.5,0.25])
a=nu.array([1.0,-1.0/3])
C=nu.array([[0,1]])
D=nu.array([[0]])
num=[1,3,3]
den=[1,2,1]
sys=signal.TransferFunction(num,den)
print sys
When I ran it, it gives:
$ python trial.py
Traceback (most recent call last):
File "trial.py", line 9, in <module>
sys=signal.TransferFunction(num,den)
AttributeError: 'module' object has no attribute 'TransferFunction'
AttributeError: 'module' object has no attribute 'TransferFunction'
This is the key phrase you want to search based on. Have you tried importing the module explicitly?
Also this could give you more information related to your problem.
Please check the scipy version you have installed, if you have an older version of scipy the TransferFunction might not be there, due to which you are seeing the AttributeError
For me your code worked fine for latest version of scipy

python opencv import error for 2.7

I tried to import the cv2 package in windows and I got the error:
>>> import numpy
>>> numpy.version.version
'1.6.1'
>>> import cv2
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x6
Traceback (most recent call last):
File "", line 1, in
import cv2
ImportError: numpy.core.multiarray failed to import
I have also tried numpy verson 1.11.1 but it didn't work.
You should ensure that you have a single version of numpy installed, assuming you are not working within a virtualenv. Python may still be loading the old numpy package. If that is the case, you will need to remove the old version, or, to make things easier in the long run, use a virtualenv with only the packages you require.
You can check the numpy path:
import numpy
print numpy.__path__

Installing python-cv from

I am following the installation process stated here. I am stuck on step 7; I get an ImportError stating:
"RuntimeError: module compiled against API version 9 but this version of numpy is 7
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import cv2
ImportError: numpy.core.multiarray failed to import"
In the instructions it recommends me to install the latest version of opencv, so as trial and error i tried an earlier model to see what would happen...i get the same thing -_-.
Could anyone point to me what I'm doing wrong, if there are no feasible solutions, is there a more stable process of doing this
Thanks in advance.
Someone experienced a similar error here. Make sure your numpy is up to date and don't forget to change the path to the new bin directory in your environment variable.

AttributeError: 'module' object (scipy) has no attribute 'misc'

I updated from ubuntu 12.04 to ubuntu 12.10 and the python module I have written suddenly no longer works with the error message that the module scipy does not have the attribute 'misc'. This worked previously. I am still using python 2.7 after the update. Here is where the code crashes
import scipy
scipy.misc.imsave(slice,dat)
Any ideas?
>>> import scipy
>>> scipy.misc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'misc'
>>>
>>>
>>> import scipy.misc
>>> scipy.misc.imsave
<function imsave at 0x19cfa28>
>>>
Which seems to be quite common with scipy.
Because you cannot directly use the misc module from scipy without explicitly import it. Here is the way of loading scipy.misc:
import scipy.misc
#Load the Lena image into an array, (yes scipy does have a lena function)
lena = scipy.misc.lena()
...
imread is depreciated after version 1.2.0 !
So to solve the problem I had to install 1.1.0 version.
pip install scipy==1.1.0
You need to explicitly import scipy.misc as:
import scipy.misc
You need to install the package pillow (formerly known as PIL), if not already installed. For image manipulation functions of scipy.misc such as imread() or imsave() to function correctly, pillow has to be installed.
To verify, either run your code again or type the below command:
scipy.misc.imread
I had a similar problem. In my case, I was trying to import comb from scipy.misc, which had been depreciated in scipy 1.0.0 (see ref here). Thus, I was inevitabely getting AttributeError: module 'scipy.misc' has no attribute 'comb'.
Replacing scipy.misc.comb with scipy.special.comb fixed the issue.

ImportError when installing NumPy for Python 2.7

EDIT: after reading this http://projects.scipy.org/numpy/ticket/1322 it seems that the NumPy version I am using doesn't work with Mac OS 10.5.x. Does anyone have access to a version of NumPy that works with Mac OS 10.5? I can't get it to compile either.
Original post ...
I am trying to use NumPy, but I'm having difficulty installing it. I'm using the installer that is available on sourceforge.
NumPy v1.5.0 (Py2.7)
Python 2.7
Mac OS 10.5.8 (PPC)
After running the installer (all I did was double-click the .pkg and follow the instructions), I try to import it ...
>>> import numpy
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import numpy
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nump/__init__.py", line 153, in <module>
import random
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/random/__init__.py", line 87, in <module>
from mtrand import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/random/mtrand.so, 2): Symbol not found: _fopen$UNIX2003
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/random/mtrand.so
Expected in: /usr/lib/libSystem.B.dylib
Does anyone have experience with this or have advice on how to fix it?
Thanks!
You can find discussion about current problems with Mac OS on the numpy mailing list, and I would recommend to discuss installation problems there, since that's were the developers are that try to fix the problems.
for example
http://groups.google.com/group/numpy/browse_thread/thread/a0ceb45b58feca2b#
and this is OS 10.5 specific
http://groups.google.com/group/numpy/browse_thread/thread/de75279785d56a25/2bfbb96e6d6c0a2e
You could join the effort, since they don't seem to have many OS 10.5 users available for testing.

Categories

Resources