Python: cannot import name 'rgb2gray' from 'skimage.color'

Viewed 8523

When I try:

>>> from skimage import io

I get at the end the following:

from ..color import rgb2gray
ImportError: cannot import name 'rgb2gray' from 'skimage.color' (C:\Users\user\A
ppData\Local\Programs\Python\Python37-32\lib\site-packages\skimage\color\__init_
_.py)

Although I have installed the packages: matplotlib, scipy, pillow, numpy and six

How can I fix it? Any help would be appreciated

4 Answers

It looks like you haven't installed scikit-image package.

Try this on terminal:

pip install -U scikit-image

And then try importing like this:

from skimage import io
from skimage.color import rgb2gray

If you still got the error or you have installed the package previously, try reinstalling the package first.

If it still don't resolve your issue, then try updating the following packages:

matplotlib, scipy, pil, numpy and six

However, try not to import all of the subpackages to improve loading time. You can however try something like:

from skimage import color
...
gray_img = color.rgb2gray(img)

If you still got errors, make sure that you are using the correct python kernel and dependent modules are updated and installed.

If that did not help either, then try Anaconda, it come with many pre-installed packages.

Leave a comment if you still have a problem :)

three ways to convert RGB2Gray:

opencv:

import cv2
img=cv2.imread("file.jpg",0)   [enter link description here][1]

or you can do this:

img=cv2.imread("file.jpg")
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

cv2.COLOR_BGR2GRAY beacause it reads BGR mode.

another methods you can look this link: enter link description here

It happened to me once when I import skimage using env conda on Jupyter. I installed by pip or conda in env, that error happened. However, after restart the Jupyter, it worked.

Related