How to set flags in nuitka to add resources to standalone exe?

493 views Asked by At

I need to compile a Python program in nuitka so that the output is one exe file with resources packed inside. I tried setting the --include-data-dir flags and all that stuff, but the compiled executable crashes if I move it to another location, saying resource files were not found.

This is what the directory looks like where all the files are located:

client/

    fnt/

        #here fonts

    img/

        #here images

    util/

        #here modules

    icon.ico

    main.py

In the terminal, being in the client folder, I set the directives:

py -m nuitka --standalone --onefile --include-data-dir=fnt=fnt --include-data-dir=img=img --windows-icon-from-ico=icon.ico main.py

Also I tried this:

py -m nuitka --standalone --onefile --include-data-dir=../client/fnt=fnt --include-data-dir=../client/img=img windows-icon-from-ico=icon.ico main.py

All the same, the program crashes and asks for files nearby.

I need to build a completely self-contained exe that doesn't require external dependencies.

What am I doing wrong?

P.S. Util is only .py files, they are compiled normally. With icon also no problems.

2

There are 2 answers

1
AudioBubble On

Maybe consider using the --include-data-file option instead of --include-data-dir. This way, the files will be included in the executable directly, allowing the program to access them without relying on external files. Make sure to specify all relevant files using this option during the compilation process. This should resolve the issue.

1
AudioBubble On

Seems like you are facing issues with the resource path when compiling the py program with Nuitka. Have you tried using the --output-dir flag to ensure that the resource paths are correctly referenced? Additionally, make sure to use the appropriate relative paths from the executable location. This way, the program can locate the necessary resources regardless of its location.