AttributeError: module 'pytesseract' has no attribute 'image_to_string' - python

> import image
> import pytesseract as pya
>
> pya.tesseract_cmd = r'C:\Users\Euphz\Documents\Artworks\PSD\Speaking
of Dogs\201710'
> print(pya.image_to_string(image.open('doggieville.png')))
Traceback (most recent call last):
File "C:\PythonProjects\pytesseract.py", line 2, in
import pytesseract as pya
File "C:\PythonProjects\pytesseract.py", line 5, in
print(pya.image_to_string(image.open('doggieville.png')))
AttributeError: module 'pytesseract' has no attribute 'image_to_string'
Why is it happening???

The problem is, you have to rename the python file to something else instead of pytesseract.py . Your python file has the same name as tesseract inbuilt function .

Can you try this?
import image
import pytesseract as pya
pya.tesseract_cmd = r'C:\Users\Euphz\Documents\Artworks\PSD\Speaking
of Dogs\201710'
print(pya.image_to_string(image.open('doggieville.png')))
The import statements need to be in seperate lines.

Related

Errors in image background remover using Python with rembg and PIL - getting error in the modules I think?

So I'm making a super simple python program using rembg and PIL that I found on the internet. I'm getting an error that seems to be an issue with the module rembg or numpy, but I can't be sure. This is what the code looks like:
from rembg import remove
from PIL import Image
input_path = 'ballroom1.jpg'
output_path = 'output.png'
input = Image.open(input_path)
output = remove(input)
output.save(output_path)
Now these are the errors:
Traceback (most recent call last):
File "D:\PyCharm\BackgroundRemover\Remove.py", line 1, in <module>
from rembg import remove
File "D:\PyCharm\Python\rembg\__init__.py", line 5, in <module>
from .bg import remove
File "D:\PyCharm\Python\rembg\bg.py", line 5, in <module>
import numpy as np
File "D:\PyCharm\Python\numpy\__init__.py", line 124, in <module>
from numpy.__config__ import show as show_config
File "D:\PyCharm\Python\numpy\__config__.py", line 12, in <module>
os.add_dll_directory(extra_dll_dir)
AttributeError: module 'os' has no attribute 'add_dll_directory'
Now, I have numpy 1.23.5 rembg 2.0.30
Any help understanding what's going on would be much appreciated.
Thanks
I've tried reinstalling both numpy and rembg but received the same errors

how to import and display images from a folder using cv2 in python

I tried to implement this piece of code
import glob
import cv2
images = [cv2.imread(file) for file in glob.glob("C:\\Users\\DELL\\OneDrive\\Desktop\\New folder\\*.jpg")]
cv2.imshow(images,mat=0)
But its showing this error:
Traceback (most recent call last):
File "C:\Users\DELL\PycharmProjects\pythonProject\learn\project3.py", line 5, in <module>
cv2.imshow(images,mat=0)
TypeError: Can't convert object of type 'list' to 'str' for 'winname'
Can anyone please help me out to resolve this problem.
import glob
import cv2
images = [cv2.imread(file) for file in glob.glob("C:\Users\DELL\OneDrive\Desktop\New folder\*.jpg")]
for i in range(len(images)):
cv2.imshow("IMG"+str(i), images[i]) # the arguments of imshow are (name of image, image object)
Hope this works!

Python 2.7 PyTesseract AttributeError: 'PixelAccess' object has no attribute 'split'

Traceback (most recent call last):
File "C:\Python27\Stuff\imagetotext.py", line 9, in <module>
i = pytesseract.image_to_string(img)
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 143, in
image_to_string
if len(image.split()) == 4:
AttributeError: 'PixelAccess' object has no attribute 'split'
So, I'm really not sure what to do with this. https://gyazo.com/63c6439285d629c72e9076c1b4a29a42 is test.png. I've tried a lot.
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
img = Image.open('test.bmp').load()
#img.load()
i = pytesseract.image_to_string(img)
print i
I've read it might be a bug with PIL, but I just have no idea.
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
img = Image.open('test.bmp')
img.load()
i = pytesseract.image_to_string(img)
print i

ImportError: No module named cvtypes

can someone help me to say that I get this error?
Traceback (most recent call last):
File "/home/xpfotografia/Documentos/deteccion4.py", line 3, in <module>
from cvtypes import cv
ImportError: No module named cvtypes
The docs at http://www.cs.unc.edu/~gb/blog/2007/02/04/python-opencv-wrapper-using-ctypes/ have:
from CVtypes import cv
win = 'Show Cam'
cv.NamedWindow(win)
# rest snipped....
as an example... so I guess you need to change your import to include a capital CV as above

Printing docstrings in Python 3

How do you print doc strings in python 3.1.x?
I tried with the re and sys modules as a test and I keep getting errors. Thanks
import re
print(re._doc_)
Traceback (most recent call last):
File "<pyshell#91>", line 1, in <module>
print(re._doc_)
AttributeError: 'module' object has no attribute '_doc_'
It's called __doc__, not _doc_.
import re
print(re.__doc__)
Works just fine.

Categories

Resources