0
I am using the Pytesseract and Opencv libraries to print a text from an image, but when trying to run the script it gives the following error:
img_text = pytesseract.image_to_string(img) Attributeerror: partially initialized module 'pytesseract' has no attribute 'image_to_string' (Most likely due to a circular import)
I have uninstalled and reinstalled pyteressact using pip3 a few times, but the error persists. I consulted some forums/tutorials and the documentation itself talks to use "image_to_string", one detail is that even though the imported pytesseract in the code, it does not provide any method. I’ll leave the code below in case there is some syntax error.
import cv2
import pytesseract
while True:
img = cv2.imread('ph2_mask_copy.png')
cv2.imshow('Image', img)
img_text = pytesseract.image_to_string(img)
print(img_text)
key = cv2.waitKey(1)
if key == 27:
break
cv2.destroyAllWindows()
Stacktrace:
Traceback (Most recent call last): File "pytesseract.py", line 2, in import pytesseract File "/home/Alan/Projects/Digitsdetection/pytesseract.py", line 7, in img_text = pytesseract.image_to_string(img) Attributeerror: partially initialized module 'pytesseract' has no attribute 'image_to_string' (Most likely due to a circular import)
puts the full stacktrace to analyze
– Lucas Miranda
@Lucasmiranda ready
– Alan Maxwell
File "pytesseract.py", line 2
. You named your file aspytesseract.py
. When you doimport pytesseract
you are importing the file itself. Avoid doing this in Python.– Woss
@Woss changed the file name and worked, thank you very much!
– Alan Maxwell
For references, see What precautions should I take when naming a Python file?
– Woss