I'm receiving "ModuleNotFoundError" when importing pytesseract - python

I have a problem when I use the pytesseract library with python
I'm on macOS Catalina 10.15.5
And I'm using an environment to run openCV Library and it works just fine, I installed pytesseract using homebrew using this command - with the environment active -:
brew install tesseract
and I checked the version of tesseract it shows v4.1.1
So I'm not sure where is the mess up

Related

How to import OpenCV into python

I have downloaded Anaconda on my Windows PC, and I have been using Spyder IDE. Now I want to do a project with OpenCV.
However, I have tried to install OpenCV using the Command Prompt and typing the following in:
pip install opencv-python
This only gives an error message and says "pip" is not recognized as a command.
Furthermore I tried to import OpenCV into Python using the following:
import cv2
This also doesn't work
I would appreciate any help in getting OpenCV working.
It depends on Your OS. Check Your pip installation with cmd: pip -V and check python with: python -V
It seems like You don't have pip installed at all.
Than import cv2 should work.

TesseractNotFoundError Using Anaconda/Jupyter

I have installed Anaconda 2018.12 (Python 3.7 version). I am trying to test out the pytesseract module but I keep encountering:
TesseractNotFoundError: C:\Program Files (x86)\Tesseract-OCR\tesseract.exe is not installed or it's not in your path
I have done:
pip install Pillow (already installed it says)
pip install pytesseract (successful)
Tried to set the tesseract_cmd to the location of tesseract (but I can't find it)
I have searched for the tesseract.exe file but cannot find it anywhere on the system so I'm struggling to understand how do I reference/import the module into a jupyter notebook if it's already been consumed into anaconda?
The code I'm trying to run is:
from PIL import Image
import pytesseract
#pytesseract.pytesseract.tesseract_cmd = r"C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe"
text = pytesseract.image_to_string(Image.open('C:\Temp\IMG_1519.jpg'))
print(text)
I'm hoping it's simple user error but any assistance would be gratefully received. Many thanks, Ben
Quoting from the PyPi page:
Python-tesseract is a wrapper for Google’s Tesseract-OCR Engine.
and (under prequisites):
Install Google Tesseract OCR (additional info how to install the engine on Linux, Mac OSX and Windows)
This means, that pytesseract is not a standalone module. It is a python wrapper for using the Google’s Tesseract-OCR Engine, which you need to install seperately

Python Import Error, Symbol not found: _iconv Referenced from:

I've successfully running Python 2.7.15 (default one) on macOS Sierra 10.12.6.
I have also installed OpenCV using pip of version 3.4.0, using this tutorial.
Screenshot: Python IDLE Screenshot showing OpenCV version on macOS
When I try to import cv2 from python IDLE it gets successfully imported, but when I try import cv2 from a python script and run as cgi script, it shows the following error:
Error Screenshot: OpenCV import error while importing and running from browser
What does the error actually mean?
How can I solve this?
Note: I've no errors while running python as CGI scripts (without importing opencv).
Note: I've even tried of installing OpenCV using Homebrew but it still produces the same error while importing OpenCV as a CGI script.
Very common error with OpenCV, the best move you can do is to install OpenCV using Anaconda.
I recommend you to fully uninstall Python and install Anaconda Python, it comes with the conda package manager that will allow you to install opencv--python easily.
https://www.anaconda.com/download/
Once Anaconda Python is installed, try the following commands:
conda install -c conda-forge opencv
conda install -c menpo opencv3

Python: Install Tesseract for Windows 7

My objective is to use OCR in Python 2.7 using Tesseract on a Windows 7 machine, but I am running into issues as for the installation process. I tried following the instruction here but the link to "tesseract-core-yyyymmdd.exe" and "tesseract-langs-yyyymmdd.exe" do not exist anymore and I can't find these .exe elsewhere online. Here's what I have done so far:
installed tesseract from its executable from official tesseract-ocr page.
installed via pip packages "wand", "PIL", "pyocr".
Now, if I do the following in Python:
from wand.image import Image
from PIL import Image as PI
import pyocr
import pyocr.builders
import io
No problem loading up these packages but pyocr.get_available_tools() gives me an empty list. I am sure this has to do with the missing installation .exe files above. Where can I find them? Is it something else that I am missing?
I just tried to set up pytesseract and it works ! I have windows 10 and python 2.7 installed.
all you need to do :
Download Visual basic C++ from http://aka.ms/vcpython27 and install it (common installation step)
Download tesseract from python via this link https://pypi.python.org/pypi/pytesseract
Unizip the file.
Go to the directory which contains the unizip file
Run this command " python setup.py install "
(Additional) to test if it's installed, go to your python shell and run this command " import pytesseract "
I hope it works !! Note pytesseract is google based OCR, it works similarly to tesseract.
Step [1] To install tesseract kindly visit
https://github.com/UB-Mannheim/tesseract/wiki
The latest installers can be downloaded from here:
e.g., tesseract-ocr-setup-3.05.02-20180621.exe, tesseract-ocr-w32-setup-v4.0.0-beta.1.20180608.exe, tesseract-ocr-w64-setup-v4.0.0-beta.1.20180608.exe (64 bit)
Step [2] Download Microsoft Visual C++ Compiler for Python 2.7 from the link given below
https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi
Step [3] Install pytesseract for binding for tesseract using pip
pip install pytesseract
Step [4] Furthermore you can install an image processing library in python, e.g., pillow:
pip install pillow
greetings!! you are done!! :)
PIP is a package manager for Python packages
Open cmd run pip search "pytesseract", you can see latest version
Run pip install pytesseract for latest version or pip install pytesseract==0.3.0 for version you want.
In windows python cmd run import pytesseract for sure installed was successful.
Install both and you are done
Binaries from:
https://github.com/UB-Mannheim/tesseract/wiki
Python Wrapper from here:
https://pypi.python.org/pypi/pytesseract

OpenCV and Anaconda Python

How can you import OpenCV to run in Python?
I ran it on a windows platform. My main problem i ran into was using Python 3.5 (presuming it was the latest) and the latest version of OpenCV but i didn't know that OpenCV sis not compatible with Python 3.5 so online video tutorials on youtube all failed miserably and i couldnt get past the import stage for almost a full day.
Here's what I have tried:
Python 3.5 (64bit) & (32bit) with OpenCV
Anaconda 3 (64bit) & (32bit) with OpenCV
Using Anaconda Python 2.7 (64bit) with OpenCV ended up working. Turns out OpenCV that I downloaded from the site is for Python 2.7.
conda install -c menpo opencv3=3.1.0
or
conda install -c anaconda opencv=2.4.10
It's a bit annoying that you need to know which collection a package is in if it isn't the standard one, but a certain search engine will find it.
you can simply activate your conda environment
conda activate "environment name"
install opencv using pip
pip install opencv-python
simply compile your code in your environment it should work
it should work.

Categories

Resources