15 Python scripts into one executable?

前端 未结 2 487
南笙
南笙 2020-12-18 03:33

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 scri

相关标签:
2条回答
  • 2020-12-18 04:14

    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.

    0 讨论(0)
  • 2020-12-18 04:15

    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'],
    )
    
    0 讨论(0)
提交回复
热议问题