I was following this guide https://realpython.com/blog/python/setting-up-a-simple-ocr-server/ and got to the part where I run cli.py python flask_server/cli.py
In my case, I was running it in Jupyter so I used this command,
! pip install --user pytesseract
But I forgot to restart the kernal. You need to restart the kernal after installing the pakcage
Python import
errors usually boils down to one of those three cases (whether is is modules you developed; or modules distributed as packages):
You did no install the required package. Googling pytesseract
tells me its an OCR that is distributed and installable using Python package manager tool pip
by running pip install pytesseract
in your favorite shell.
You did install the package, but is is not in your python path.
(Less often) You did install the package, and it is in your python path, but you used a name already in user by Python, and the two are conflicting.
In your case, I strongly think this is the first one. Case 2. and 3. can be assessed by calling python -v your_script.py
as described in this answer.
I had the same error. My solution is
$ pip3 install pytesseract
since I have python 2 and python 3 installed together.
I had a similar error. So I hope to help people with this kind of problems.
In my case, I tried to run python code using pytesseract lib on Raspberry pi 3.
$ pip install pillow
$ pip install pytesseract
(followed by https://www.pyimagesearch.com/2017/07/10/using-tesseract-ocr-python/)
and then, I made an example.py to test.
try:
import Image
except ImportError:
from PIL import Image
from pytesseract import *
print(pytesseract.image_to_string(Image.open('YOUR_IMAGE_PATH')))
and then, when I run this code, I got below error like you. ImportError: No module named pytesseract
After I saw the @Bertrand Caron's answer, I found a solution. My problem was package library path.
I also have multiple versions of python, 2.7 and 3.5, like a writer.
When I run command $python --version
on linux, the result is Python 2.7.13.
In my case, when I installed a pytesseract package, it was stored in "/usr/local/lib/python3.5/dist-packages/pytesseract".
And When I ran $python -v example.py
, I found the referenced packages path hadn't been same with upper pytesseract package directory.
cf.
installed pytesseract path : /usr/local/lib/python3.5/dist-packages/pytesseract
actual referenced lib path, when running : /usr/lib/python2.7/dist-packages/
So, I copied pytesseract, located in "/usr/local/lib/python3.5/dist-packages/pytesseract" to "/usr/lib/python2.7/dist-packages/"
Then, Solved!