import pytesseract
import PIL
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
Im trying that code alone with many other ways to type the pile path as in double '\' etc but I still continue to get the error:
ModuleNotFoundError: No module named 'PIL'
In shell, run:
pip install Pillow
The error means you are missing some modules.
pip install --upgrade --force-reinstall Pillow
resolved my issue
Related
I have been working on this code for long time , I had run in several ide but all shows same error and i am bit confuse now and i need a proper solution so that code may works
import os
import cv2 as cv
import numpy as np
people=['emily','emma','jim parson']
haar_cas=cv.CascadeClassifier('haar_face.xml')
DIR=r'G:\opencv\faces'
features=[]
labels=[]
def train_face():
for person in people:
paths=os.path.join(DIR,person)
label=people.index(person)
for img in os.listdir(paths):
img_path=os.path.join(paths,img)
img_array=cv.imread(img_path)
gray=cv.cvtColor(img_array,cv.COLOR_BGR2GRAY)
faces_rect=haar_cas.detectMultiScale(gray,1.1,2)
for(x,y,w,h) in faces_rect:
faces_roi= gray[y:y+h,x:x+w]
features.append(faces_roi)
labels.append(label)
train_face()
feature=np.array(features,dtype='object')
label=np.array(labels)
# print(f'length of the feature={len(features)}')
# print(f'lenght of the labels={len(labels)}')
face_reconizer=cv.face.LBPHFaceReconizer_create()
np.save('feature.npy',feature)
np.save('label.py',label)
the output of the code is
File "G:\opencv\face_reconization.py", line 28, in <module>
face_reconizer=cv.face.LBPHFaceReconizer_create()
AttributeError: module 'cv2.face' has no attribute 'LBPHFaceReconizer_create'
If you installed opencv by running pip install opencv-python there are some missing packages there so you need to run pip install opencv-contrib-python to install the full version.
If that doesn't work try reinstalling opencv
pip3 uninstall opencv-contrib-python
python -m pip install opencv-contrib-python
The PIL module should be installed because when I run the pip install pillow I get this message: Requirement already satisfied: pillow in [my installation route]. But, when I try to import this into a file, I get this error:
ModuleNotFoundError: No module named 'Pillow'
What am I doing wrong?
this has worked for me if your using vscode try install by typing py -m pip install pillow
from PIL import ImageTk,Image
Pillow is a fork of PIL, and the import is carried over.
import PIL
Should do the trick. The documentation has additional details:
https://pillow.readthedocs.io/en/stable/installation.html
I am creating a Heroku app in which I am using PIL and from PIL import Image.
When I run heroku local, it returns ModuleNotFoundError: No module named 'Image'. I have tried using Pillow instead of PIL, but it returns the same error. PIL and Pillow are both in my requirements.txt.
A link to my full github repo is: https://github.com/maivey/flower-image-classifier
Please help as I do not understand why it will not recognize PIL or Pillow
Maybe you need to install them.
If you use anaconda: conda install PIL
If you use pip: pip install PIL
Thanks
I am trying to use pytesseract for OCR, on a raspberry pi using Raspbian
I have read several questions on this topic, but can't find an answer that works, they usually say to install pytesseract with pip, and I did it.
my code is very simple:
import pytesseract
from PIL import Image
print(pytesseract.image_to_string(Image.open('test.jpg')))
But it returns error message : "ImportError: No module named 'pytesseract' .
I have installed tesseracrt-ocr (the whereis tesseract-ocr command returns /usr/share/tesseract-ocr)
I have installed pytesseract with pip install tesseract (which returns successfully installed Pillow-4.3.0 olefile-0.44 pytesseract-0.1.7 ... but the whereis pytesseract command does not return anything --> a problem?).
Do you have any idea of the problem I have ?
See after installing pytesseract ,using
<cmd>C:\> pip install pytesseract
Try :
import pytesseract
If above is not working then it has do something with the installation ,
Check if pytesseract folder is available under "\Python27\Lib\site-packages" ,
Try the above command from site packages, Hope this helps ,
Else there is something wrong with installation .
Add this line in your code
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
set your path where tesseract-ocr is installed and also add this path to your window environment variable.Also check this link Tesseract installation for complete installation of tesseract.
I have trying to use pytesseract for OCR (extracting text from the image). I have successfully installed pytessearct by using the command -
pip install pytessearct
When I try to install it again, it clearly says -
Requirement already satisfied (use --upgrade to upgrade):
pytesseract in ./site-packages
This means pytessearct is installed successfully. When i try to import this package in my iPython notebook using -
import pytessearct
It throws an error -
ImportError: No module named pytesseract
Why is that happening?
To use Python-tesseract - requires python 2.5+ or python 3.x - first you have to install PIL and pytesseract packages through pip:
pip install Pillow
pip install pytesseract
Then you have to download and install the tesseract OCR:
https://sourceforge.net/projects/tesseract-ocr-alt/?source=typ_redirect
As far as I know it automatically adds it to your PATH variable.
Then use it like this way:
import pytesseract
from PIL import Image
img = Image.open('Capture.PNG')
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
print( pytesseract.image_to_string(img) )
I hope it helps :)