I have installed the PILLOW module in Windows 8.1 for Python 3 using the below command.
pip install pillow
The installation was a success.
Unfortunately when I tried to import the image sub-module within it using the below statement I got an import error.
from PIL import image
Error: ImportError: cannot import name 'image' from 'PIL' (C:\Program Files\Python38\lib\site-packages\PIL_init_.py)
Although the below statement is giving me an error for the 'PIL' .
image = PIL.Image.open("Capture Image.PNG")
Error: Undefined variable: ' PIL'Python(undefined-variable)
I have tried similar posts listed below, but they didn't help me to solve the issue.
Pip install Pillow: "no module named Pillow?"
Pillow installed, but getting "no module named pillow" when importing
Python pillow module not importing properly
Could you please someone explain what I'm missing here?
Regards,
Chiranthaka
#dragon2fly Many thanks for solving the issue. Please refer the below snippet for the complete source code.
from PIL import Image
image = Image.open("Capture_image.png")
print(image.size)
Related
I have code that requires: import cv2
but get the error message: Exception has occurred: ModuleNotFoundError
No module named 'cv2'
I have seen exactly the same question before, but all the suggestions fail. The question is 6 years old and hence am repeating it.
various failed suggestions:
conda install --channel https://conda.anaconda.org/menpo opencv3
conda install -c menpo opencv
I am using Windows 10 and have python 3.8.1 running.
I have removed cv2 from the code which works without error and resolves the issue.
The link here (at time of writing, version 4.1.2.3) describes the opencv-python package:
opencv-python link
With the following description of cv2 towards the bottom of the page:
It's easier for users to understand opencv-python than cv2 and it makes it easier to find the package with search engines. cv2 (old interface in old OpenCV versions was named as cv) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet. Changing the import name or behaviour would be also confusing to experienced users who are accustomed to the import cv2.
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
In case you run into this error from inside a Jupyter Notebook, try restarting the kernel as suggested in this GitHub issue.
That solved the problem for me.
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.
I have installed Pillow but when I try to import the Image module I get an exception:
How can I resolve it?
i think you should try it like this:
from PIL import Image
please refer documentation for more clarity
I'm relatively new to python, so please excuse my ignorance on what could be a very easy fix. I am running python 3.6 through the Rodeo IDE, and it has been great, as it is similar to R-Studio (which I am very familiar with). As an aspiring data scientist, I am trying to learn how to fit regression and time series models to data, and all of the tutorials that I have found all say that I need various packages, all of which should be included in the Anaconda library. After downloading and re-downloading Python, Rodeo, and Anaconda, and trying various online fixes, I have been unable to successfully load the scikit-learn and the statsmodels modules.
#here is everything I have tried.
#using pip
! pip install 'statsmodels'
! pip install 'scikit-learn'
! pip install 'sklearn'
I don't get any errors here, and to be honest I'm kind of confused as to what this actually does, but I have seen many people online always suggest that this is a big problem when trying to import modules.
#using import
import sklearn
import statsmodels
from sklearn import datasets
import statsmodels.api as sm
all of the above give me the same error:
import statsmodels.api as sm
ImportError: No module named 'statsmodels'
ImportError: Traceback (most recent call last)
ipython-input-184-6030a6549dc0 in module()
----> 1 import statsmodels.api as sm
ImportError: No module named 'statsmodels'
I have tried to set my working directory to the Anaconda 3 file that has all of the packages and rerunning the above code with no success.
I'm thinking that the most likely problem has to do with my inexperience, and it is probably a simple fix. Is it possible that the IDE is bad or anaconda just doesn't like me?
So keeping all of the above in mind, the question is, how can I import these modules successfully so that I can access their functionality?
Option 1:
After installing packages with pip, try closing and reopening your IDE/Jupyter Notebook and try again.
This is a known bug that Jake VanderPlas outlined here
Option 2:
Don't put quotations around your pip messages.
!pip install -U statsmodels
!pip install scikit-learn
Option 3:
Also are you using Anaconda? If you are, you should already have scikit-learn. If you are trying inside Rodeo, I think you need to set your path inside Rodeo. Open Rodeo and set the Python Path to your fresh anaconda. See here
So I trying to install and run from MSFT the cntk, you know, just for fun. Anyway, I keep getting this error which says:
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Now I have looked around here a little and I found a post saying that I needed to install the latest version of NumPy, but when I go to do that, I get back this:
Requirement already satisfied: NumPy in c:\users\username\appdata\local\continuum\anaconda3\envs\cntk-py34\lib\site-packages
SO I really have no idea what is going on here.
Anyway, thanks in advance.
Is your IDE linked to Anaconda env? If you open up the Anaconda prompt and import numpy do you get the same error?
You probably have an environment outside of Anaconda which does not have numpy installed.
In my case, I was executing [filename].py from the Anaconda prompt as I would a batch file and was getting this error. I confirmed numpy was install by executing pip list.
Funning python and passing the script file name as an argument, eg python [filename].py, correctly imported the numpy module and executed the script without error.