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

I am trying to use the run_tesseract function to get an hocr output for extracting text from an image for Bank receipt images.However I am getting the above error message. I have installed Tesseract-OCR on my laptop, and have also added its path to my System Path variable.I have a windows 10 64 bit operating system,
I have tried uninstalling and reinstalling it also but to no avail.
import glob
import pytesseract
from PIL import Image
img_files=glob.glob('./NACH/*.jpg')
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract OCR\\tesseract.exe'
#im=Image.open(img_files[0])
#im.load()
pytesseract.run_tesseract(img_files[0],'output',lang='eng',config='hocr')
I get the following complete Error Message:
AttributeError Traceback (most recent call last)
in
4 im=Image.open(img_files[0])
5 im.load()
----> 6 pytesseract.run_tesseract(img_files[0],'output',lang='eng',config='hocr')
7 #text = pytesseract.image_to_string(im)
8 #if os.path.isfile('output.html'):AttributeError: module
'pytesseract' has no attribute 'run_tesseract'

Replace pytesseract.run_tesseract() with pytesseract.pytesseract.run_tesseract().
Credit Nithin in the comments. Adding this as an answer to close it out.

Related

"module 'torchtext.data' has no attribute 'Field'"

import torchtext
ENGLISH = torchtext.data.Field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
Error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-2a3d11c77e7d> in <module>
----> 1 ENGLISH = torchtext.data.Field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
AttributeError: module 'torchtext.data' has no attribute 'Field'
It won't import torchtext.data.Field for some reason even though that's whats in the docs
[BC Breaking] Legacy
In v0.9.0 release, we move the following legacy code to torchtext.legacy. This is part of the work to revamp the torchtext library and the motivation has been discussed in Issue #664:
torchtext.legacy.data.field
torchtext.legacy.data.batch
torchtext.legacy.data.example
torchtext.legacy.data.iterator
torchtext.legacy.data.pipeline
torchtext.legacy.datasets
We have a migration tutorial to help users switch to the torchtext datasets in v0.9.0 release. For the users who still want the legacy components, they can add legacy to the import path.
Try it with ENGLISH = torchtext.legacy.data.field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")

'FileDataset' object has no attribute 'DoseGrid'

I have been trying to use the dicompyler-core to put together two dose grids from two different dose dicoms.
import pydicom
import numpy as np
import os
import glob
from dicompylercore import dicomparser, dvh, dvhcalc
from dicompylercore import dose
I keep receiving this error while trying to import dose
ImportError Traceback (most recent call last)
<ipython-input-120-6605335fa321> in <module>
5 import glob
6 from dicompylercore import dicomparser, dvh, dvhcalc
----> 7 from dicompylercore import dose
ImportError: cannot import name 'dose' from 'dicompylercore'
Because of this import error, I think that is why there is no attribute to be found when I try and add the two dose grids together
dose1 = dicomparser.DicomParser("RD.CW.dcm")
dose2 = dicomparser.DicomParser("RD.CCW.dcm")
grid_1 = dose.DoseGrid()
grid_2 = dose.DoseGrid()
grid_sum = grid_1 + grid_2
grid_sum.save_dcm("grid_sum.dcm")
It gives me this error
~\Anaconda3\lib\site-packages\pydicom\dataset.py in __getattr__(self, name)
550 if tag is None: # `name` isn't a DICOM element keyword
551 # Try the base class attribute getter (fix for issue 332)
--> 552 return super(Dataset, self).__getattribute__(name)
553 tag = Tag(tag)
554 if tag not in self._dict: # DICOM DataElement not in the Dataset
AttributeError: 'FileDataset' object has no attribute 'DoseGrid'
I am new to working with dicom files and with dicompylercore. I am unsure if this is related to the dicom files I am working itself or if there is some issue with the dicomplyercore package itself. Are there any suggestions on what I could do to fix this?
The dose module has been added to dicompylercore after the last PyPi release, so you have to install the version from GitHub, if you want to use it:
pip install git+https://github.com/dicompyler/dicompyler-core
I'm not sure how stable this version is, but you can ask about the next release on the development site.

Error while opening the image in opencv and python

I am trying to start with basics of opencv with python but when i executed the below code :
import cv2
import numpy as np
img = cv2.imread('bg.jpg',cv2.IMREAD_GRAYSCALE)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
But i am getting this error:-
Traceback (most recent call last):
File "F:\OpenCV Programs\OpenCV1.py", line 7, in <module>
cv2.imshow('image',img)
error: C:\build\master_winpack-bindings-win32-vc14-
static\opencv\modules\highgui\src\window.cpp:331: error: (-215) size.width>0
&& size.height>0 in function cv::imshow
Plz help me out thank you..!
The code you posted works, if there is an image called bg.jpg within the same directory where you are running the code.
Anyway, you could try to reference the full path to the image:
import os
img_path = os.path.join(os.getcwd(), 'bg.jpg')
img = cv2.imread(img_path,cv2.IMREAD_GRAYSCALE)
The image you attempt to load does not exist.
As you cannot display a non-existing image you get an error messsage for trying.
You'll most likely messed up the path. Maybe use an absolute path to the image.

AttributeError: 'module' object has no attribute 'version' Canopy

Hi I am going to preface this with I could just be really dumb so don't overlook that, but suddenly when opening canopy today I wasn't able to run one of my typical scripts with the error AttributeError: 'module' object has no attribute ' version' when trying to load pandas. From what I can gather it seems when bumpy is called through pandas it fails. I checked my working directory for files named numpy.py to see if I idiotically named a file numpy but failed to find such a file. I also attempted to uninstall and reinstall both numpy and pandas from the package manager in canopy. Any suggestions?
%run "/Users/jim/Documents/ORAL-PAT-2.5-3.5plotly.py"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/jim/Documents/ORAL-PAT-2.5-3.5plotly.py in <module>()
1 #import the modules you need
----> 2 import pandas as pd
3 import numpy as np
4 import plotly.plotly as py
5 import plotly.tools as tls
/Users/jim/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/__init__.py in <module>()
20
21 # numpy compat
---> 22 from pandas.compat.numpy_compat import *
23
24 try:
/Users/jim/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/compat/numpy_compat.py in <module>()
13
14 # numpy versioning
---> 15 _np_version = np.version.short_version
16 _np_version_under1p8 = LooseVersion(_np_version) < '1.8'
17 _np_version_under1p9 = LooseVersion(_np_version) < '1.9'
AttributeError: 'module' object has no attribute 'version'
Just had the same problem after downgrading Pandas and upgrading again to fix another issue. This is just a hack, but you could try this:
Open ...pandas/compat/numpy_compat.py and replace np.version.short_version with np._np_version
Hope that helps!

Python PIL NameError global name Image is not defined

I installed PIL 1.1.7 using the executable for Python 2.7. But when I run this code :
import requests
from PIL import *
def main() :
target = "http://target/image.php" #returns binary data for a PNG.
cookies = {"mycookie1", "mycookie2"}
r = requests.get(target, cookies=cookies)
im = Image.open(r.content) #r.content contains binary data for the PNG.
print im
if __name__ == "__main__" :
main()
It gives the error :
Traceback (most recent call last):
File "D:\Programming\Python\code\eg_cc1.py", line 17, in <module>
main()
File "D:\Programming\Python\code\eg_cc1.py", line 13, in main
im = Image.open(r.content)
NameError: global name 'Image' is not defined
I installed PIL in Lib\site-packages.
You need to explicitly import the Image module:
>>> from PIL import *
>>> Image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Image' is not defined
>>> import PIL.Image
>>> Image
<module 'Image' from 'c:\Python27\lib\site-packages\PIL\Image.pyc'>
>>>
Or just
>>> import Image
Use
from PIL import Image
This way it will work, and your code will be forward-compatible with Pillow. On the other hand, import Image will not work with Pillow.
The development of PIL has been stopped in mid 2011, without any official announcement or explication. Pillow is a fork of original PIL and is actively developed.
If
import Image
is not working.
Try:
from PIL import Image
There is compatibility issue with all the packages in PIL. Try downloading PIL package manually for the latest version.
Actually worked with this in Python 3.2 Version, everything is working fine.

Categories

Resources