Ido Barash
Ido Barash

Reputation: 5132

generate an applet using py2app with PyQt5 dependencies errors

Im using PyQT5 to make an applet that I wish to wrap with py2app.

While the app is working perfectly when I run it via pycharm, unfortunatly when I try to wrap it as python it fails to run.

So I created a simple case to simulate it. Something simple with a file picket and a text input that does nothing except show errors.

Still many dependencies are missing.

checking for any import problems
Modules not found (unconditional imports):
 * _io._WindowsConsoleIO (importlib._bootstrap_external)
 * _overlapped (asyncio.windows_events)
 * com (com.sun.jna)
 * com.jna (com.sun)
 * com.sun (com.sun.jna.platform)
 * jinja2 (pkg_resources._vendor.pyparsing.diagram)
 * pyparsing (pkg_resources._vendor.pyparsing.diagram)
 * railroad (pkg_resources._vendor.pyparsing.diagram)
 * win32com (win32com)
 * win32com.shell (win32com.shell)
 * win32com.shellcon (win32com.shell)

Modules not found (conditional imports):
 * _manylinux (pkg_resources._vendor.packaging._manylinux)
 * com (pkg_resources._vendor.appdirs)
 * com.sun.jna (pkg_resources._vendor.appdirs)
 * com.sun.jna.platform (pkg_resources._vendor.appdirs)
 * pep517 (importlib.metadata)
 * win32com (pkg_resources._vendor.appdirs)
 * win32com.shell (pkg_resources._vendor.appdirs)

Done!

When I use my real code that uses pandas and stuff I get lots more missing dependencies.

I have no idea what to do... All the threads I could find are years old.

Iuse: python 3.10.13 PyQt5. 5.15.10 py2app 0.28.7

I use pyenv and I am running the flow within my virtual env. I did find that my PYTHONPATH was empty.... but setting it to point to the env was not successful.

Please help Thanks

Here is the code:

app.py

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout, QFileDialog, QHBoxLayout, QSpacerItem, QSizePolicy, QFrame, \
    QMessageBox


class App(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        main_layout = QVBoxLayout()
        self.setLayout(main_layout)

        def create_file_input_section(label_text, default_text):
            layout = QVBoxLayout()
            label = QLabel(label_text)
            layout.addWidget(label)
            layout2 = QHBoxLayout()
            line_edit = QLineEdit(default_text)
            line_edit.setFixedWidth(400)
            button = QPushButton('Browse...')
            button.setFixedWidth(100)
            layout2.addWidget(line_edit)
            layout2.addWidget(button)
            layout.addLayout(layout2)

            button.clicked.connect(lambda: self.openFileNameDialog(line_edit))

            main_layout.addLayout(layout)
            main_layout.addItem(QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed))  
            return line_edit

        self.input_file = create_file_input_section('CSV File:', '')

        horizontal_line = QFrame()
        horizontal_line.setFrameShape(QFrame.HLine)
        horizontal_line.setFrameShadow(QFrame.Sunken)
        main_layout.addWidget(horizontal_line)

        self.label_limit = QLabel('Limit:')
        self.input_limit = QLineEdit('10')
        self.input_limit.setFixedWidth(400)
        main_layout.addWidget(self.label_limit)
        main_layout.addWidget(self.input_limit)

        main_layout.addItem(QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed))  

        horizontal_line = QFrame()
        horizontal_line.setFrameShape(QFrame.HLine)
        horizontal_line.setFrameShadow(QFrame.Sunken)
        main_layout.addWidget(horizontal_line)

        main_layout.addItem(QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Fixed))  

        self.run_button = QPushButton('Run', self)
        self.run_button.clicked.connect(self.run_script)
        main_layout.addWidget(self.run_button)

        self.setWindowTitle('TEST!!!')
        self.setFixedWidth(600)  

    def openFileNameDialog(self, line_edit):
        options = QFileDialog.Options()
        fileName, _ = QFileDialog.getOpenFileName(self, "Select CSV File", "", "*.csv", options=options)
        if fileName:
            line_edit.setText(fileName)

    def run_script(self):
        print("Script called with:")
        file = self.input_file.text()
        limit = self.input_limit.text()

        if not file:
            QMessageBox.critical(self, "Error", "file is missing.")
            return

        try:
            limit = int(limit)
        except Exception as e:
            QMessageBox.critical(self, "Error", "Limits must be numbers.")
            return

        QMessageBox.critical(self, "Error", "SUCCESS")
        return


def main():
    app = QApplication(sys.argv)
    ex = App()
    ex.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

setup.py

from setuptools import setup

APP = ['app.py']
DATA_FILES = []
OPTIONS = {
    'argv_emulation': True,
    'packages': ['PyQt5'],
    'includes': []
}

setup(
    app=APP,
    name="Test",
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

Thanks

Upvotes: 0

Views: 35

Answers (0)

Related Questions