0

I'm trying to build and distribute a python app with PyOxidizer but i cannot seem to get it to work. I tried other tools apart from PyOxidizer (like pyinstaller and pynsist) but to no avail, those are even worse and i can't even get the app to see all modules. My project is structured like so:

Proj:
    -Interface:
        -main.py
    -User:
        -file1.py ...
        -Tests:
            -file2.py ...
        -Utilities:
            -file3.py

To use Pyoxidizer, i made a setup like:

from setuptools import setup, find_packages

setup(
    name='XXXX',
    version='1.0',
    description='XXXX',
    author='AXXXl',
    author_email='XXXX',
    packages=find_packages(),
    install_requires=['QLed', 'configparser', 'lxml', 'shiboken6', 'pyserial', 'PySide6', 'PyQt5'],
    entry_points={'console_scripts': ['SFT=Interface.mainWindow:main', ], },
    package_data={'': []},
    zip_safe=False,
)

And i have a .bzl file like this one:

def make_exe():
    dist = default_python_distribution()

    policy = dist.make_python_packaging_policy()
   
    policy.resources_location = "filesystem-relative:prefix"

    python_config = dist.make_python_interpreter_config()

    python_config.run_command = "from Interface.mainWindow import main; main()"

    exe = dist.to_python_executable(
        name="SFT",

        # If no argument passed, the default `PythonPackagingPolicy` for the
        # distribution is used.
        packaging_policy=policy,

        # If no argument passed, the default `PythonInterpreterConfig` is used.
        config=python_config,
    )

    
    exe.add_python_resources(exe.setup_py_install(package_path=CWD))

    return exe

def make_embedded_resources(exe):
    return exe.to_embedded_resources()

def make_install(exe):
    # Create an object that represents our installed application file layout.
    files = FileManifest()

    # Add the generated executable to our install layout in the root directory.
    files.add_python_resource(".", exe)

    return files

def register_code_signers():
    if not VARS.get("ENABLE_CODE_SIGNING"):
        return


# Call our function to set up automatic code signers.
register_code_signers()

# Tell PyOxidizer about the build targets defined above.
register_target("exe", make_exe)
register_target("resources", make_embedded_resources, depends=["exe"], default_build_script=True)
register_target("install", make_install, depends=["exe"], default=True)
# register_target("msi_installer", make_msi, depends=["exe"])

# Resolve whatever targets the invoker of this configuration file is requesting
# be resolved.
resolve_targets()

In mainWindow.py i have a function main() that looks like this and works perfectly when started from the IDE:

def main():
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.showMaximized()
    sys.exit(app.exec())


if __name__ == "__main__":
    main()

The main problem is that after i try to open the installed program, the console outputs the title message and then shuts off. Can i do something about this? Are there better alternatives to PyOxidizer that would allow me to distribute this software?

Andrei
  • 59
  • 5
  • I never used PyOxydizer, but are you sure you've to explicitly call the `main` in `Interface.mainWindow:main`? – musicamante Jul 25 '22 at 14:05
  • @musicamante i'm not really sure, as PyOxidizer's documentation is surprisingly confusing, but as far as i've seen in some [examples](http://www.dlab.ninja/2021/09/how-to-create-python-executables-with.html), pyoxidizer is unable to get the entrypoint from the setup file and requires an additional launch command in the `.bzl` file. Can i acheive this packaging and distributions in other ways? – Andrei Jul 25 '22 at 18:41

0 Answers0