Reputation: 31
I'm currently building an app that uses OCR to extract data from PDF files using PYQT5, and I need to use the terminal to convert the pdf into jpeg's before running the OCR; however, when I run this subprocess after compiling it crashes, but it works perfectly if I don't compile the program.
It seems to me that the problem lies within the subprocess call. I've tried many different ways, but I don't know why my app keeps crashing after I compile and run the conversion.
NOTE: For PDF to JPEG I'm using ImageMagick
Currently using to compile:
py2applet --make-setup main.py
python3 setup.py py2app
Converter.py:
from subprocess import call
from PIL import Image
import pytesseract
from PyQt5 import QtWidgets
from ocrgui import Ui_MainWindow
class ImageConverter(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.show()
self.sbmt_btn_convert.clicked.connect(self.convert_image)
def convert_image(self): #Converts image into jpeg
text = str(self.input_convert.text())
output = str(self.output_convert.text())
convert = 'converted.jpeg'
call('convert -density 300 ' + text + ' ' + convert, shell=True)
im = Image.open(convert)
text = pytesseract.image_to_string(im, lang = 'eng')
file = open(output,'w')
file.write(text)
file.close()
call('rm converted.jpeg', shell=True)
print('Succesfully created')
Main.py:
import sys
from PyQt5.QtWidgets import QApplication
from calculator import CalculatorWindow
app = QApplication(sys.argv)
calculator = CalculatorWindow()
sys.exit(app.exec())
Upvotes: 0
Views: 170
Reputation: 13691
I think that problem in the next module:
pathPython\Lib\site-packages\PIL\ImageQt.py
Try to put # on the next lines:
...
try:
from PyQt5.QtGui import QImage, qRgba, QPixmap
from PyQt5.QtCore import QBuffer, QIODevice
qt_version = '5'
except (ImportError, RuntimeError):
print("except (ImportError, RuntimeError):!!!!!!!!!!!!")
#try:
# from PyQt4.QtGui import QImage, qRgba, QPixmap
# from PyQt4.QtCore import QBuffer, QIODevice
# qt_version = '4'
#except (ImportError, RuntimeError):
# try:
# from PySide.QtGui import QImage, qRgba, QPixmap
# from PySide.QtCore import QBuffer, QIODevice
# qt_version = 'side'
# except ImportError:
# qt_is_installed = False
...
Upvotes: 0