Script_Coded
Script_Coded

Reputation: 710

Python portable pyinstaller

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.

Upvotes: 2

Views: 5061

Answers (1)

Mikhail Gerasimov
Mikhail Gerasimov

Reputation: 39546

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)

Upvotes: 3

Related Questions