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

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')

Related

Pillow can't import

I have a Problem with the Pillow module.
So basically i tried the methods on this website installing it per pip install Pillow and also importing it per from PIL import Image and import PIL none of them worked
I would really appreciate it if someone helped
and thanks for reading. This is my code:
import pyautogui
import pyscreeze
from PIL import Image
lkchat = pyautogui.locateCenterOnScreen("python.png")
print ("lkchat")
I'm getting the following error message:
from PIL import Image
ImportError: No module named PIL
Kitty Star i would like to suggest you that replace PIL with pillow and then install pillow if your code does not run let me know the next error.

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

Trying to plot an image in python (using scipy and numpy)

I'm trying to run this code:
http://forumbilder.se/H8CIL/skarmavbild-2018-10-08-kl-21-22-19
so I change it to this one:
and then I got this:
http://forumbilder.se/H8CIL/skarmavbild-2018-10-08-kl-21-22-47
What's wrong? I'm a newbie, and fyi, I'm only have anaconda installed to my Python 3.6.6 .
Regards,
--
and in code:
from skimage import data
photo_data = misc.imageio('./wifire/sd-3layers.jpg')
type(photo_data)
and i get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-c8186ae7b8e9> in <module>()
1 from skimage import data
2
----> 3 photo_data = misc.imageio('./wifire/sd-3layers.jpg')
4
5 type(photo_data)
AttributeError: module 'scipy.misc' has no attribute 'imageio'
So I change it to:
You have to import imageio. You might have to install the library if you don't have it yet (on your terminal):
pip install imageio
(If you don't have pip install yet, you can do on your terminal sudo easy_install pip, see here: How do I install pip on macOS or OS X?)
And then your code to use read the image with imageio:
import imageio
im = imageio.imread('./wifire/sd-3layers.jpg')
type(im)
To display your image, you can use visvis library (https://imageio.readthedocs.io/en/stable/examples.html). Then you total code would be:
import imageio
import visvis as vv
im = imageio.imread('./wifire/sd-3layers.jpg')
vv.imshow(im)

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__

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.

Categories

Resources