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

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.

Related

AttributeError: module 'pandas.compat' has no attribute 'iteritems'

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.

Cannot import name 'imread', 'imresize', 'imsave' anaconda (windows)

I am trying to import image to python but end up getting the same error again and again.
I have tried most of the solutions mentioned about this problem on multiple discussion threads but none of them have solved this issue of mine.
I have installed Pillow but still the error prevails. Would really appreciate some guidance on how to resolve this issue.
from scipy.misc import imread, imresize, imsave
import numpy as np
ImportError Traceback (most recent call last)
<ipython-input-6-c8bc16b68368> in <module>
----> 1 from scipy.misc import imread, imresize, imsave
2 import numpy as np
ImportError: cannot import name 'imread'
The library you're looking scipy.misc.imread is deprecated. You can use imageio. First install Pillow and then install imageio
pip install Pillow imageio
Then you can use,
imageio.imread('image1.png')
imageio.imread('image2.png', array)
But you cannot resize in imageio. Use numpy for that.
What is your version? I think scipy.misc.imread is deprecated. Use imageio
import imageio
image = imageio.imread('pic.png')

How can I Fix an ImportError

So I am stuck on how can I fix the import error for imresize. I installed all the things I needed like installing Pillow but I haven't been able to find a solution. Also the code that I trying to run is from this github link https://github.com/CSAILVision/IBD
Also side note I do not own this code nor was not the original arthor of it. This is for a research project that I am apart of. In addition I try asked the original arthor with a fix but haven't heard back from them at all.
Installing Pillow, Replacing with code: from scipy.misc.pilutil import imread, installing Pillow-3.3.1-cp27-cp27m-win32.whl, Unninstall Pil and installing Pillow, Reinstalling Pillow.
from util.image_operation import *
from PIL import Image
import numpy as np
from imageio import imresize, imread
from visualize.plot import random_color
from torch.autograd import Variable as V
import torch
I expect it to run but print out the image but it doesn't.
Traceback (most recent call last):
File "test.py", line 4, in <module>
from loader.model_loader import loadmodel
File "/home/joshuayun/Desktop/IBD/loader/model_loader.py", line 5, in <module>
from util.feature_operation import hook_feature, hook_grad
File "/home/joshuayun/Desktop/IBD/util/feature_operation.py", line 6, in <module>
from imageio import imresize, imread, imsave
ImportError: cannot import name 'imresize'
If you want to work with the code as is, i would recommend creating a new environment, and installing an old version of scipy (0.19.1 should do the trick). In your new environment, assuming you are using conda, do:
conda install scipy==0.19.1
If you use pip instead:
pip install scipy==0.19.1
Since scipy 1.3.0rc1 resize has been removed.
I had the same problem, I had scipy 1.4. I did the following and it worked -
pip install scipy==1.1.0

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__

Categories

Resources