Nefariis Nefariis - 1 year ago 82
Python Question

15 Python scripts into one executable?

Ive been tinkering around all day with solutions from here and here:

How would I combine multiple .py files into one .exe with Py2Exe

Packaging multiple scripts in PyInstaller

but Its not quite working the way I thought it might.

I have a program that Ive been working on for the last 6 months and I just sourced out one of its features to another developer who did his work in Python.

What I would like to do is use his scripts without making the user have to download and install python.

The problem as I see it is that 1 python script calls the other 14 python scripts for various tasks.

So what I'm asking is whats the best way to go about this?

Is it possible to package 15 scripts and all their dependencies into 1 exe that I can call normally? or is there another way that I can package the initial script into an exe and that exe can call the .py scripts normally? or should I just say f' it and include a python installer with my setup file?

This is for Python 2.7.6 btw

And this is how the initial script calls the other scripts.

import printSub as ps
import arrayWorker as aw
import arrayBuilder as ab
import rootWorker as rw
import validateData as vd

If this was you trying to incorporate these scripts, how would you go about it?


Answer Source

You can really use py2exe, it behaves the way you want.

See answer to the mentioned question: How would I combine multiple .py files into one .exe with Py2Exe

Usually, py2exe bundles your main script to exe file and all your dependent scripts (it parses your imports and finds all nescessary python files) to library zip file (pyc files only). Also it collects dependent DLL libraries and copies them to distribution directory so you can distribute whole directory and user can run exe file from this directory. The benefit is that you can have a large number of scripts - smaller exe files - to use one large library zip file and DLLs.

Alternatively, you can configure py2exe to bundle all your scripts and requirements to 1 standalone exe file. Exe file consists of main script, dependent python files and all DLLs. I am using these options in to accomplish this:

  options = {         
    'py2exe' : {
        'compressed': 2, 
        'optimize': 2,
        'bundle_files': 1,
        'excludes': excludes}
  console = [""],

Working code:

from distutils.core import setup
import py2exe, sys, os

  options = {         
    'py2exe' : {
        'compressed': 1, 
        'optimize': 2,
        'bundle_files': 3, #Options 1 & 2 do not work on a 64bit system
        'dist_dir': 'dist',  # Put .exe in dist/
        'xref': False,
        'skip_archive': False,
        'ascii': False,
  console = [''],