First, remember to add the line
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'
where
C:/Program Files/Tesseract-OCR/tesseract.exe
is the location where your tesseract is installed.
You have indicated that the image file is a string, which is ok, but you did not add an extension of the image!
For example,
you would have written
image_file = 'location.png'
. The extension jpeg, or any other format your image is holding.
Then, instead of writing
text = pyt.image_to_string(image_file)
, write
text = pyt.image_to_string(img)
because its an image you are parsing and not a string.
The rest of the code is ok.
Note: You may need to specify the exact location of the image; for example 'C:/Users/Dismas/Desktop/opencv-python/image_text.png'
But if you still get the same problem, you can use the link How to install tesseract OCR. I followed the steps therein as they are.
I had a similar problem like yours, but now I am sorted.
The image below may be a good source of better understanding
screenshot