TesseractError: (2, 'Usage: pytesseract [-l lang] input_file') error - ocr

I am getting the error TesseractError: (2, 'Usage: pytesseract [-l lang] input_file'). Using ! sudo apt install but still getting the error in colab.
Its a JPG I am trying to read.
-----------------------------code -------------------------------------
! apt install tesseract-ocr
! apt install libtesseract-dev
! sudo apt install tesseract-ocr
! pip install Pillow
! pip install pytesseract
import pytesseract
import shutil
import os
import cv2
import random
from google.colab import files
from io import BytesIO
from PIL import Image,ImageFilter
!pip install pdf2image
!apt-get install -y poppler-utils
from pdf2image import convert_from_path
#from google.colab import drive
!sudo apt install tesseract-ocr
!pip install pytesseract
!pip install tesseract
pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'
image_path_in_colab = 'Pillow block drawing.jpg'
img = cv2.imread('Pillow block drawing.jpg')
custom_config = r'-l eng --psm 6'
pytesseract.image_to_string(img, config=custom_config)
extractedInformation = pytesseract.image_to_string(Image.open(image_path_in_colab))
print(extractedInformation)

install:
!sudo apt install tesseract-ocr
Change:
pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'
to:
pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'

you need to set the tesseract location as env variable . Like this
pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'
The following line is wrong
pytesseract.pytesseract.tesseract_cmd =
r'/usr/local/bin/pytesseract'

Related

AttributeError: module 'keras.api._v2.keras' has no attribute 'utils'

OS: MacOS Monterey (12.4)
Chip: Apple Silicon M1
Env: Conda 4.12.0
Python: 3.9.12
TensorFlow version: 2.9.0, installed through pip install tensorflow-macos
Error message:
Traceback (most recent call last):
File "/Users/okihita/PycharmProjects/TFFlowerClassification/main.py", line 20, in <module>
training_dataset = tf.keras.utils.image_dataset_from_directory(
AttributeError: module 'keras.api._v2.keras' has no attribute 'utils'
Here's my main.py code:
import pathlib
import tensorflow as tf
from PIL import Image
data_dir = pathlib.Path('aksara-batak/toba')
aksara = list(data_dir.glob('a/*'))
img_height = 30
img_width = 30
training_dataset = tf.keras.utils.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width)
)
Did I import the wrong version of TensorFlow?

generate html and json reports for selenium python automation test using pytest

I have a selenium python automation test, it works fine, now I want to generate Html and JSON reports and have screenshots in the report using pytest. I am new to automation and python so I am not much aware of how its done.
following is my code
test_screenshot.py
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pytest_html
from selenium.common.exceptions import InvalidSessionIdException
def test_Openurl(setup):
driver = setup["driver"]
url = setup["url"]
try:
driver.get(url)
except Exception as e:
print(e.message)
assert driver.current_url == URL
driver.save_screenshot("ss.png")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.save_screenshot("ss1.png")
driver.close()
conftest.py
import pytest
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
def pytest_addoption(parser):
parser.addoption("--url", action="store", default="https://google.com/")
#pytest.fixture()
def setup(pytestconfig):
s = Service("C:/Users/Yash/Downloads/chromedriver_win32/chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.maximize_window()
yield {"driver":driver, "url": pytestconfig.getoption("url")}
I ran this using
pytest test_screenshot.py --url "https://www.netflix.com/in/"
Test case is passed. How do I generate HTML and JSON report?
I tried this
pytest -v -s --json-report --json-report-indent=4 --json-report-file=report/report.json --html=report/report.html test_screenshot.py
but got this error
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --json-report --json-report-indent=4 --json-report-file=report/report.json
inifile: None
You need to install these two libraries : https://pypi.org/project/pytest-json-report/ & https://pypi.org/project/pytest-html/

Django 2.0 - Python3.6 - CentOS 7 - MySQL connections

i try to install my website on a webserver which is in CentOS 7 with Django 2.0.6 and Python 3.6.
I installed : mysql-connector = 2.1.6,
mysql-connector-python = 8.0.11,
MySQL-python = 1.2.5,
mysqlclient = 1.3.12,
PyMySQL = 0.8.1
And when i run this command :
python3.6 manage.py migrate
I have this error :
File "MYPYTHONPATH/python3.6/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 1.2.5
But in the base.py file :
try:
import MySQLdb as Database
except ImportError as err:
raise ImproperlyConfigured(
'Error loading MySQLdb module.\n'
'Did you install mysqlclient?'
) from err
from MySQLdb.constants import CLIENT, FIELD_TYPE # isort:skip
from MySQLdb.converters import conversions # isort:skip
# Some of these import MySQLdb, so import them after checking if it's installed.
from .client import DatabaseClient # isort:skip
from .creation import DatabaseCreation # isort:skip
from .features import DatabaseFeatures # isort:skip
from .introspection import DatabaseIntrospection # isort:skip
from .operations import DatabaseOperations # isort:skip
from .schema import DatabaseSchemaEditor # isort:skip
from .validation import DatabaseValidation # isort:skip
version = Database.version_info
if version < (1, 3, 3):
raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
I dont understand what can i do for resolving this kind of problem !
I hope someone can help me on =)
Okay, i solved it with the answer of this thread.
No module named MySQLdb
pip install PyMySQL
and then add this two lines to your Project/Project/init.py
import pymysql
pymysql.install_as_MySQLdb()
Works on WIN and python 3.3+

Compilation error in Cython

I installed cython in lubuntu and trying complie 'hello World' program using terminal command
python3 setup.py build_ext
but gcc returns compilation error.
Here is my setup.py code
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("cython.pyx")
)
and cython.pyx code
print("hello World")
got it by using terminal command
python3 setup.py build_ext --inplace
and changed setup.py to
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("hello", ["cython.pyx"])]
setup(
name = 'Hello world app',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)

How to use nltk3 for python33?

I successfully installed NLTK 2.0.4, but when I tried to download the NLTK packages, i.e.
nltk.download('stopwords')
it doesn't work, so I am trying to install an updated version of NLTK for python 3 but it gives this error:
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Prashant\AppData\Roaming\Python\Python33\site-packages\nltk\_
nit__.py", line 37
except IOError, ex:
^
SyntaxError: invalid syntax
Is there any way to install NLTK for python33?
First install python3-pip then use it to install pyyaml
$ sudo apt-get install python3-pip
$ sudo pip3 install pyyaml
$ wget http://www.nltk.org/nltk3-alpha/nltk-3.0a3.tar.gz
$ tar -xzvf nltk-3.0a3.tar.gz
$ cd nltk-3.0a3/
$ sudo python3 setup.py install
$ python3
>>> import nltk
>>> from nltk.corpus import brown
>>> print(brown.sents()[0])
['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an', 'investigation', 'of', "Atlanta's", 'recent', 'primary', 'election', 'produced', '``', 'no', 'evidence', "''", 'that', 'any', 'irregularities', 'took', 'place', '.']