15 Python scripts into one executable?

只谈情不闲聊 提交于 2019-11-29 07:22:33
Jiri

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 setup.py to accomplish this:

setup( 
  ...
  options = {         
    'py2exe' : {
        'compressed': 2, 
        'optimize': 2,
        'bundle_files': 1,
        'excludes': excludes}
        },                   
  zipfile=None, 
  console = ["your_main_script.py"],
  ...
)

Working code:

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

sys.argv.append('py2exe')
setup( 
  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,
        }
        },                   
  zipfile=None, 
  console = ['thisProject.py'],
)
K246

Following setup.py (in the source dir):

from distutils.core import setup
import py2exe

setup(console = ['multiple.py'])

And then running as:

  python setup.py py2exe

works fine for me. I didn't have to give any other options to make it work with multiple scripts.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!