开发者

Python 2.7 (with Tkinter) project into a stand-alone exe?

I've searched this for ages and tried everything. Just can't make it work.

What I want to do is to make a stand-alone exe of my small program that uses Tkinter, for Windows. This far I've accomplished to make it an exe, however the dist/ folder including a folder tcl/ and an extra exe-file. How to get rid 开发者_Go百科of these?

Also, I haven't been able to make a working exe. Here's my setup.py:

from distutils.core import setup
import py2exe
import sys
if len(sys.argv) == 1:
    sys.argv.append("py2exe")

setup(
    options = {
        "py2exe": {"compressed": 1, "optimize": 2, "ascii": 1, "bundle_files": 1, "includes": ["Tkinter"]}
        },
        zipfile = None,
        windows = [
        {
            "script": "hello.py",
            "icon_resources": [(0, "icon_16.ico")]
        }
    ]
)

With this code I get a notice "This program has stopped responding" instantly after running it.

By removing the option "ascii", the program doesn't work and leaves a logfile:

Traceback (most recent call last):
  File "hello.py", line 1, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "Tkinter.pyo", line 38, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "FixTk.pyo", line 56, in <module>
  File "FixTk.pyo", line 23, in convert_path
LookupError: unknown encoding: mbcs

I was very optimistic about Python as it seemed really nice to code and find help for, but this is something I can't code anything without. Any help is appreciated. I'm a total newcomer.


I think there is a bug with the way that it bundles tkinter, you cannot optimize or bundle tkinter in python, take those options out and try running it.


Anything in the "tcl" folder is required by Tkinter. Tkinter is actually linking to a Tcl interpreter (which means you can run Tcl commands in Python!). Because of this, you need everything that a Tcl interpreter needs (including support for Tk).

The error you get is an encoding error, and in your options I see "ascii": 1. Get rid of that and it should solve the problem.

Also, if you plan on making an installer for this compiled program, there is no real reason to compress the program with "compressed": 1 (it only needs to be small when it's distributed).


You could try using an alternate solution provided at the location below which basically uses an installer method. I wasn't able to bundle that tcl folder in the exe as well, so I guess this should be a better solution.

http://www.py2exe.org/index.cgi/SingleFileExecutable

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜