Frage

I've been trying to compile python code into a single exe, and i didn't manage to do it correctly.

  1. I've tried pyinstaller, and this is the .spec file:

    # -*- mode: python -*-
    a = Analysis([os.path.join(HOMEPATH,'support\\_mountzlib.py'), os.path.join(HOMEPATH,'support\\useUnicode.py'), 'programs\\toolbox.py'],
             pathex=['C:\\Users\\Ronaldo\\Desktop\\Python\\pyinstaller'])
    pyz = PYZ(a.pure)
    exe = EXE( pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name=os.path.join('dist', 'program.exe'),
          debug=False,
          strip=False,
          upx=True,
          console=False )
    

    Pyinstaller compiled fine, created a single exe file which worked, but apparently other users that didn't have the same version of python installed (2.7.2) couldn't run it. Doesn't give any error, It simply doesn't launch. I've tried it by sending it to a few friends, and also tried on a virtual machine.

  2. Tried py2exe. When it comes to compiling (with all the libraries next to it, and the rest of files) it works fine. I tried compiling it to a single file but the compiled exe file gave me a " toolbox.exe has stopped working" error. Here's the error report, just in case, might be useful:

    Problem signature:
      Problem Event Name:   APPCRASH
      Application Name: toolbox.exe
      Application Version:  0.0.0.0
      Application Timestamp:    49180193
      Fault Module Name:    StackHash_0a9e
      Fault Module Version: 0.0.0.0
      Fault Module Timestamp:   00000000
      Exception Code:   c0000005
      Exception Offset: 01b61fcb
      OS Version:   6.1.7601.2.1.0.256.1
      Locale ID:    1033
      Additional Information 1: 0a9e
      Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
      Additional Information 3: 0a9e
      Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
    

    The setup.py file is:

    from distutils.core import setup
    import py2exe, sys, os
    
    sys.argv.append('py2exe')
    
    setup(
        options = {'py2exe': {'bundle_files': 1}},
        windows = [{'script': "toolbox.py"}],
        zipfile = None,
    ) single.py file:
    

    And here's the single.py:

    import os, sys, ctypes
    
    ctypes.windll.user32.MessageBoxA(0,
        "curdir: %s\nexedir: %s\nsys.winver: %s" % (
            os.path.abspath(os.curdir),
            os.path.abspath(os.path.dirname(sys.argv[0])),
            sys.winver,
        ), "%s - Message" % os.path.basename(sys.executable), 0x30
    )
    

The program I wrote uses tkinter, sys, random and win32clipboard(pywin) modules. What am I doing wrong? Are there any other, better compilers?

Update: By Joël's tip, I compiled with debug, and with console mode. Still didn't work for users that don't have python 2.7. This is the error message:

C:\Users\XXXXX\Desktop>program.exe
Found embedded PKG: C:\Users\XXXXX\Desktop\program.exe
Extracting binaries
Setting up to run child
Setting magic environment var
Creating child process
Waiting for child process to finish...
Found embedded PKG: C:\Users\XXXXX\Desktop\program.exe
workpath: C:/Users/XXXXX/AppData/Local/Temp/_MEI14042/
manifestpath: C:/Users/XXXXX/AppData/Local/Temp/_MEI14042/program.exe.manifest
Activation context created
Activation context activated
C:\Users\XXXXX\AppData\Local\Temp\_MEI14042\python27.dll
Manipulating evironment
PYTHONPATH=C:/Users/XXXXX/AppData/Local/Temp/_MEI14042;C:/Users/XXXXX/Desktop
importing modules from CArchive
extracted iu
extracted struct
extracted archive
Installing import hooks
outPYZ1.pyz

I really hope this serves as help for the possible answer.

War es hilfreich?

Lösung

My two cents: did you make a test using the debug option of PyInstaller?

Just update your specfile:

exe = EXE( pyz,
           [...]
           debug=True,
           [...])

(Note: in order to avoid numerous message boxes, you may want to set console output: console=True)

Maybe it would return some useful data. Please provide us with output in this case (if there's any).


According to the output you get, this is quite a common problem, because if PyInstaller resolves dependencies for your modules, dependencies of dependencies may be forgotten.

In your case, Tcl is missing, and this is needed by some Tkinter library: you should take a look here: Python, Pyinstaller creating shortcuts in windows

According to documentation:

Elaborating on Makespec.py, this is the supported command line: python Makespec.py [opts] [ ...] Where allowed OPTIONS are:

[...]

-K, --tk include TCL/TK in the deployment.

You may make a try with this argument, and check the impact on your spec file. I bet it's an addition in the modules taken into account in Analysis or in the EXE function.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top