Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

python - How to compile all resources into one executable file?

I've wrote GTK application with python.

All graphical user interface is in glade file, and there are some images used. I wish to compile my application into EXEcutable file. For that I'm using PyInstaller compiler and UPX packer.

I've done as manual says:

python Configure.py
python Makespec.py --onefile --windowed --upx /path/to/yourscript.py
python Build.py /path/to/yourscript.spec

PyInstaller works perfectly and create one exe file. But to make my application work correctly i have to copy my glade and image files into exe's folder.

Is there any way to compile those files into executable?

I've edited my spec file in various ways but i can not achieve what i want. Spec file below only copies file to directory, but does not compile into executable file

# -*- mode: python -*-
a = Analysis([os.path.join(HOMEPATH,'support\_mountzlib.py'), os.path.join(HOMEPATH,'support\useUnicode.py'), 'r:\connection\main.py'],
             pathex=['C:\Documents and Settings\Lixas\Desktop\pyinstaller-1.5-rc1'])

pyz = PYZ(a.pure)

exe = EXE( pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name=os.path.join('dist', 'NetworkChecker.exe'),
          debug=False,
          strip=False,
          upx=True,
          console=False,
          icon='r:\connection\ikona.ico'        )

coll = COLLECT(
    exe,
    [('gui.glade', 'r:\connection\gui.glade', 'DATA')],
    [('question16.png', 'r:\connection\question16.png', 'DATA')],
#   a.binaries,
#   strip=False,
    upx=True,
    name='distFinal')

I wish to have only one executable file with everything included into

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With a few changes, you can incorporate everything into your source code and thus into your executable file.

If you run gdk-pixbuf-csource on your image files, you can convert them into strings, which you can then load using gtk.gdk.pixbuf_new_from_inline().

You can also include your Glade file as a string in the program and then load it using gtk.Builder.add_from_string().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...