pyinstallernuitka

How to bundle third party .exe in stanadlone Python executable


I'm writing scripts to automate some task to be executed from windows machine to remote ubuntu server, which uses putty-tools like plink.exe, pscp.exe and psftp.exe.

My python program is able to run successfully but I'm trying to build a single independent standalone file which can be run in another PC even if that PC do not have these putty tools available.

I'm using below commands

python -m nuitka --enable-plugin=tk-inter --windows-disable-console --onefile --standalone my_program.py

I'also found related question here but it was not answered Bundle third party .exe in Python code and produce another portable .exe

Can someone please help me on this.


Solution

  • Fortunately I found answer for my question by reading the nuitka user manual, we need to use one of the below format based on the requirement. In my case I used second one.

    # This will find a file near your onefile.exe
    open(os.path.join(os.path.dirname(sys.argv[0]), "user-provided-file.txt"))
    # This will find a file inside your onefile.exe
    open(os.path.join(os.path.dirname(__file__), "user-provided-file.txt"))
    

    And while packing my command become something like below,here it will include all the files available in source directory to target directory in "onefile.exe"

    python -m nuitka --enable-plugin=tk-inter --windows-disable-console --onefile
    --include-data-dir=<source>=<target> --standalone my_program.py