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
Related
I am trying to import pandas-ml but I get this import error.
What might be the issue?
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-fd3c3c034481> in <module>
----> 1 import pandas_ml as pml
AttributeError: module 'pandas.compat' has no attribute 'iteritems' ```
File "/usr/local/lib/python3.7/site-packages/pandas_ml/core/accessor.py", line 81, in _update_method_mapper
for key, class_dict in compat.iteritems(cls._method_mapper):
AttributeError: module 'pandas.compat' has no attribute 'iteritems'
I have the same error too with python3.7. I solved it with changing iteritems() to items() .
There are two lines on accessor.py under #classmethod, change them into:
for key, class_dict in cls._method_mapper.items():
'
'
'
class_dict = {k: getattr(cls, m) for k, m in class_dict.items()}
For my version,
I have also encounter another import error ImportError: cannot import name 'range' from 'pandas.compat'in File "/usr/local/lib/python3.7/site-packages/pandas_ml/confusion_matrix/stats.py". just delete from pandas.compat import range would do.
Reference:
https://github.com/pandas-dev/pandas/commit/e26e2dfe6e93922830fb5fb7868b87238b85911a#diff-21f71fbdb0d3dfa55dc948e2ddcddc92
The iteritems attribute for pandas.compat appears to be have been removed recently, as seen here (tip from this source).
In other words, your current version of pandas is incompatible with pandas-ml currently.
The GitHub issue suggests to maybe downgrade your pandas version.
# Installed using pip
pip install pandas==0.24.2
# Installed using conda
conda install pandas==0.24.2
You can run the following in the Python REPL to double check the pandas package version to see if it is greater than 0.25.0.
import pandas
print(pandas.__version__)
I had the same problem.
I found out, that pandas_ml is not compatible with the current verions of scikit-learn and pandas.
So I wrote a fix and made a pull request on github.
Have a look here https://github.com/AlfredoCubitos/pandas-ml or here https://github.com/pandas-ml/pandas-ml/pull/132.
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.
After installing the facebook-sdk module here, and looking at other solutions here and elsewhere, I keep getting this error:
Traceback (most recent call last):
File "facebook.py", line 1, in <module>
import facebook
File "/home/facebook/facebook.py", line 3, in <module>
graph = facebook.GraphAPI(access_token='ACCESS TOKEN HERE')
AttributeError: 'module' object has no attribute 'GraphAPI'
For this very simple python code to authenticate...
import facebook
graph = facebook.GraphAPI(access_token='ACCESS TOKEN HERE')
print 'Workinnnn'
It says my module is installed and up to date, and I have installed both within (as suggested) a virtualenv and outside, and still get the error. I also definitely HAVE the module in usr/local/lib/python etc. dist packages... and it contains the class GraphAPI
Has anyone got a suggestion either:
1) What might be going wrong?
2) What to try to fix it? UNinstall something?
3) If there is another way other than pip to install the module... I don't normally use pip (but definitely have it installed and installed facebook-sdk from it) so if there's another way then I'd like to try...
Cheers :/
Solution = don't name your script the same as your module.
I'm an idiot, sigh...
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.
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.