No module named pytesseract error - python

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.

Related

Why do I get an error trying to use pytesseract?

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

Python2 Packages not recoganised by Python3

I have installed both python2.7 and python3.5 in my Ubuntu. I mostly use Python3.5 only. I was trying to import some libraries and use them in my program
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
n = input()
print(n)
print(pytesseract.image_to_string(Image.open(str(n))))
When I run this code with Python3 filename.py I am getting a package not found error.Then I tried running it with Python filename.py then I am getting the desired output. Then I added the input() line and tried to run it and it started throwing an error because input() was introduced only in Python3
Then I tried to locate the pacakages that I have installed namely "PIL(python3-imaging), tesseract, pytesseract" and their location goes something like usr/local/lib/Python/. Since I am new to this packages and stuff my guess is that the erroris caused because they are installed in Python2.7 related files and not in Python3 files.
How can I solve this problem? Any help would be appreciated.
try this line to install the package you want to use
python3 -m pip install PIL tesseract pytesseract

Importing pytesseract

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

PyTesseract not working

After installing PyTesseract, I went into my Mac's terminal to make sure it works. I got it to output into a text file perfectly find, but after running this code in Enthought Canopy:
import pytesseract
from PIL import Image
print pytesseract.image_to_string(Image.open('/Users/Nelson/Desktop/Projects/R6S Statistics/OCR/ocr-test.png'))
I get this:
AttributeError: 'ImagingDecoder' object has no attribute 'pulls_fd'
This error comes from the PIL file:
/Users/Nelson/Desktop/Canopy/User/lib/python2.7/site-packages/PIL/ImageFile.pyc
I was able to resolve this error by restarting my Jupyter notebook kernel. I performed a pip install --upgrade scikit-image in the middle of a notebook session and got this error. The upgrade installed a newer version of PIL (v4.0) but the previously installed (v3.2) version has already been loaded into memory.

No module named Image

Sorry for my grammar, I don't speak English.
After I set filebrowser, tinymce, and grappelli, I get this error: No module named Image
try:
from PIL import Image
except ImportError:
import Image
I set it to PIL but it didn't solve the problem.
my platform windows
If i want: pip install PIL
`c:\Users\Kim\BitNami DjangoStack projects\homex8>pip install PIL
Downloading/unpacking PIL
Running setup.py egg_info for package PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
Installing collected packages: PIL
Running setup.py install for PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
building '_imaging' extension
error: Unable to find vcvarsall.bat`
I do not understand what that means
Solved problem.
reinstall PIL with easy_install, and more movements, here are the details.
You are missing PIL (Python Image Library and Imaging package). To install PIL I used
pip install pillow
For my machine running Mac OSX 10.6.8, I downloaded Imaging package and installed it from source.
http://effbot.org/downloads/Imaging-1.1.6.tar.gz and cd into Download directory. Then run these:
$ gunzip Imaging-1.1.6.tar.gz
$ tar xvf Imaging-1.1.6.tar
$ cd Imaging-1.1.6
$ python setup.py install
Or if you have PIP installed in your Mac
pip install http://effbot.org/downloads/Imaging-1.1.6.tar.gz
then you can use:
from PIL import Image
in your python code.
Did you setup PIL module? Link
You can try to reinstall it on your computer.
It is changed to : from PIL.Image import core as image
for new versions.
You can this query:
pip install image
I had pillow installed, and still, I got the error that you mentioned. But after I executed the above command, the error vanished. And My program worked perfectly.
Problem:
~$ simple-image-reducer
Traceback (most recent call last):
File "/usr/bin/simple-image-reducer", line 28, in <module>
import Image
**ImportError: No module named Image**
Reason:
Image != image
Solution:
1) make sure it is available
python -m pip install Image
2) where is it available?
sudo find ~ -name image -type d
-->> directory /home/MyHomeDir/.local/lib/python2.7/site-packages/image
->> OK
3) make simple-image-reducer understand via link:
ln -s ~/.local/lib/python2.7/site-packages/image
~/.local/lib/python2.7/site-packages/Image
4)
invoke simple-image-reducer again.
Works:-)
If you are trying to just show the image on your notebook, below simply does the job
from IPython.display import Image
Image(url= "Link to the image ending with file format such as, .jpg or .png")

Categories

Resources