2

I'm building an application where I'd like my users to be able to create executables with only a couple of clicks for some settings. It's a GUI application made with Tkinter where there is a page with some options. These options are then supposed to be written to a premade Python script. That will be no problem to make. The tricky part is compiling the script into an executable (.exe). I've always been using PyInstaller for making executables, but that's only on my own local computer. What if I want to pack my application and have PyInstaller bundled? I know PyInstaller requires pywin32, which means that has to be bundled too.

I'm completely lost on how to bundle PyInstaller with my application.

I've been doing a lot of googling on the matter, but can't seem to find any help at all. The closest I got was this post, which didn't help very much.

Community
  • 1
  • 1
Script_Coded
  • 709
  • 8
  • 21

1 Answers1

3

Try to use Nuitka. I tried some alternatives for Python (including PyInstaller) and like this one most. With Nuitka you can compile your script (and all modules it need) to standalone .exe file. Then you can create installer with many available options.

Here's user manual, here's example of command (I used for my project):

nuitka --standalone --recurse-all --recurse-stdlib --remove-output --windows-disable-console --recurse-directory=YOUR_PROJECT_DIR

Upd: How to run nuitka inside script:

import os
import subprocess

project_dir = os.path.abspath('project')
project_main = os.path.abspath('project\\main.py')

subprocess.call([
    'nuitka', '--standalone', '--recurse-all', '--recurse-stdlib', '--remove-output',
    '--windows-disable-console', 
    # '--windows-icon={}'.format(icon_path),
    '--recurse-directory={}'.format(project_dir), 
    project_main
    ], shell=True)
Community
  • 1
  • 1
Mikhail Gerasimov
  • 36,989
  • 16
  • 116
  • 159
  • That's an interesting little program, but can i bundle it with my application? I can't seem to find anything about that in the docs. Although I can use `import nuitka` – Script_Coded Mar 07 '16 at 11:38
  • @Script_Coded, you can import nuitka and use it as module, but if you just want to create .exe using console, just use it as console command. You've already installed it, right? Now just type in console "nuitka --help", you will see list of options this util support. – Mikhail Gerasimov Mar 07 '16 at 12:24
  • That's indeed one way to go, using the console. But I'd like to be able to do it inside my script. Using something like this `nuitka.compile("myprogram.py", "--windows-disable-console")` – Script_Coded Mar 07 '16 at 12:39
  • 1
    @Script_Coded I don't know how to use nuitka's functions, but you can use subprocess inside script. I updated answer with some example code. – Mikhail Gerasimov Mar 07 '16 at 12:50
  • Unfortunately, nuitka --standalone --recurse-all --recurse-stdlib --remove-output --windows-disable-console --recurse-directory=C:\Users\Bain3\1\hello.py provides nothing for me. nuitka --recurse-all --recurse-directory=plugin_dir hello.py works, though creates a whole host of errors – Tetora Oct 30 '17 at 08:38
  • @HaydenDarcy did you try `--recurse-directory=C:\Users\Bain3\1 hello.py`? – Mikhail Gerasimov Oct 30 '17 at 10:45
  • @MikhailGerasimov Yeah unfortunately did not help. I've asked a question here https://stackoverflow.com/questions/47007017/nuitka-not-compiling-an-exe-with-nuitka-recurse-all-hello-py-error and put a bounty here: https://stackoverflow.com/questions/33104873/nuitka-on-windows . Looks like I'll have to learn C# to compile an exe though... :/. I believe someone had the same question unanswered years ago so I'm not holding my breath. – Tetora Oct 30 '17 at 10:49
  • Also, Nuitka requires MinGW64, which is insanely hard to install on Windows. – The Daleks stand with Ukraine May 22 '20 at 17:38