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
451 views
in Technique[技术] by (71.8m points)

python - creating .exe file with cx_freeze for a tkinter interface

I have searched for this answer all around the place, but i can't find an answer. I have a python script (3.3) that has an interface with tkinter. I used cx_freeze to create an executable out of it, got a build folder with some files and folders in it. I double clicked on the .exe file and nothing happened. I'm using the following setup:

import sys

from cx_Freeze import setup, Executable



base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
        name = "simple_Tkinter",
        version = "0.1",
        description = "Sample cx_Freeze Tkinter script",
        executables = [Executable("the timer.py", base = base)])

If i just open my code and run it the interface works perfectly. I do not get any error messages while doing the build (at least none that i can see... btw, how do i verify this?). Any ideas on what the problem could be? or any other alternative modules?

Thanks!! :)

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

I'd make this a comment but I don't have the reputation yet...

Any warnings/errors from the compilation output/logs?

Anything when you run the executable at the command prompt?

Does your executable need libraries that cx_freeze isn't finding?

You'll likely need to specify additional options like included libraries... Tweaking the example in the cx_freeze documentation you can specify to include TKinter:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"includes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
    name = "simple_Tkinter",
    version = "0.1",
    description = "Sample cx_Freeze Tkinter script",
    options = {"build_exe": build_exe_options},
    executables = [Executable("the timer.py", base = base)])

setup(  name = "guifoo",
        version = "0.1",
        description = "My GUI application!",
        options = {"build_exe": build_exe_options},
        executables = [Executable("guifoo.py", base=base)])

I know I've had lots of fun issues getting py2exe to work with PySide/PyQt4, matplotlib, numpy, etc. Some modules, like matplotlib, even provide a method to list all the data files necessary to build/distribute an application (matplotlib.get_py2exe_datafiles()). Solutions for Enthought's TraitsUI utilize glob to grab the directories of files needed. My point is, because module imports can be dynamic, messy, or black-magical in some libraries, many of the build utilities are unable to locate all the required resources. Also, once your executable is working, if you find stuff in the distribution you know your application won't need, you might can exclude it with additional options, which helps trim bloat from your distribution. Hopefully TKinter won't be too hard to get working - it appears others on StackOverflow were successful.

I'm sorry I don't have a rock solid solution, but I'm trying to help where I can! Good luck!


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

...