Cx_freeze 不适用于 Python 3.6.2 的 Win 10
Cx_freeze is not working on Win 10 with Python 3.6.2
我开始了解 Python。我正在尝试将 Python Tkinter 应用程序转换为 exe 文件。当不涉及 Tkinter 时,转换为 exe 工作正常。我尝试了 setup.py 的示例文件和 Tkinter 应用程序,您可以在 cx_Freeze [http://cx-freeze.readthedocs.io/en/latest/index.html] 的官方网站上找到它们,但在 CMD 中仍然出现很多错误 [例如:KeyError: 'TCL_LIBRARY'
]运行构建命令时。官方网站上说支持Python 3.6。
这里是setup.py的官方例子:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [
Executable('app.py', base=base)
]
setup(name='simple_Tkinter',
version='0.1',
description='Sample cx_Freeze Tkinter script',
executables=executables
)
这里是测试 Tkinter 应用程序的官方示例:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
try:
from tkinter import Tk, Label, Button, BOTTOM
except ImportError:
from Tkinter import Tk, Label, Button, BOTTOM
root = Tk()
root.title('Button')
Label(text='I am a button').pack(pady=15)
Button(text='Button').pack(side=BOTTOM)
root.mainloop()
您可以尝试使用 Pyinstaller 而不是 cx_freeze,它将完成与您尝试完成的完全相同的工作。
从 pip 继续输入
pip install pyinstaller
然后在你的程序目录中 运行 pyinstaller yourprogram.py
我开始了解 Python。我正在尝试将 Python Tkinter 应用程序转换为 exe 文件。当不涉及 Tkinter 时,转换为 exe 工作正常。我尝试了 setup.py 的示例文件和 Tkinter 应用程序,您可以在 cx_Freeze [http://cx-freeze.readthedocs.io/en/latest/index.html] 的官方网站上找到它们,但在 CMD 中仍然出现很多错误 [例如:KeyError: 'TCL_LIBRARY'
]运行构建命令时。官方网站上说支持Python 3.6。
这里是setup.py的官方例子:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [
Executable('app.py', base=base)
]
setup(name='simple_Tkinter',
version='0.1',
description='Sample cx_Freeze Tkinter script',
executables=executables
)
这里是测试 Tkinter 应用程序的官方示例:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
try:
from tkinter import Tk, Label, Button, BOTTOM
except ImportError:
from Tkinter import Tk, Label, Button, BOTTOM
root = Tk()
root.title('Button')
Label(text='I am a button').pack(pady=15)
Button(text='Button').pack(side=BOTTOM)
root.mainloop()
您可以尝试使用 Pyinstaller 而不是 cx_freeze,它将完成与您尝试完成的完全相同的工作。
从 pip 继续输入
pip install pyinstaller
然后在你的程序目录中 运行 pyinstaller yourprogram.py