tkbx
tkbx

Reputation: 16285

wxPython to exe with PyInstaller?

I'm trying to get a wxPython app working as an exe. I've heard that PyInstaller is now superior to py2exe. I'd like to include my .ico and two .png files that the script requires to run. What would the spec file for this look like? I can't seem to find a decent example anywhere. I have PyInstaller installed, but I can't find this "makespec" anywhere.

Upvotes: 2

Views: 2950

Answers (3)

user1292828
user1292828

Reputation: 741

a = Analysis(['script.py'],
             pathex=['D:\\source-control\\GITHUB\\projectname'],
             hiddenimports=[],
             hookspath=None,)

a.datas += [( 'images', r'C:\Users\igorl\Pictures\hzgJUXi5l4o.jpg', 'DATA')]

pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name=os.path.join('dist', 'script.exe'),
          debug=False,
          strip=None,
          upx=True,
          console=False )

Upvotes: 1

g.d.d.c
g.d.d.c

Reputation: 47988

Checking for sys.frozen is a really good approach. You can also look into img2py which will let you load the binary data for images into a .py file. Later, instead of having to open files, they can be imported.

Upvotes: 1

ChrisC
ChrisC

Reputation: 1272

In my PyInstaller projects, I'd normally just have a runtime check to see if the app's frozen and adjust the paths to the bitmaps accordingly. So something like this to handle PyInstaller and regular Python application:

def app_path():
    """Returns the base application path."""
    if hasattr(sys, 'frozen'):
        # Handles PyInstaller
        return os.path.dirname(sys.executable)
    return os.path.dirname(__file__)

Upvotes: 3

Related Questions