Python3.3 cx_freeze exe编译

时间:2013-10-03 04:12:32

标签: python compilation exe python-3.3 cx-freeze

编译完成后,终端会立即退出,尽管input()函数会等待程序中的用户输入。从cmd提示符运行可执行文件给了我以下内容:

C:\Python33\build\exe.win-amd64-3.3>chat.exe Traceback (most recent
call last):   File
"C:\Python33\lib\site-packages\cx_Freeze\initscripts\Console3.py",
line 27, in <module>
    exec(code, m.__dict__)   File "chat.py", line 28, in <module>   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in
_find_and_load   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 1525, in
_find_and_load_unlocked   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 497, in
set_package_wrapper   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 510, in
set_load er_wrapper   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 608, in
_require s_frozen_wrapper   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 713, in
load_mod ule   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 313, in
_call_with_frames_removed   File "C:\Python\64-bit\3.3\lib\threading.py", line 11, in <module>   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in
_find_and_load   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 1525, in
_find_and_load_unlocked   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 497, in
set_package_wrapper   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 510, in
set_loader_wrapper   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 608, in
_requires_frozen_wrapper   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 713, in
load_module   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 313, in
_call_with_frames_removed   File "C:\Python\64-bit\3.3\lib\traceback.py", line 3, in <module>   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in
_find_and_load   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 1525, in
_find_and_load_unlocked   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 497, in
set_package_wrapper   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 510, in
set_loader_wrapper   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 608, in
_requires_frozen_wrapper   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 713, in
load_module   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 313, in
_call_with_frames_removed   File "C:\Python\64-bit\3.3\lib\linecache.py", line 10, in <module>   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in
_find_and_load   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 1525, in
_find_and_load_unlocked   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 497, in
set_package_wrapper   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 510, in
set_loader_wrapper   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 608, in
_requires_frozen_wrapper   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 713, in
load_module   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 313, in _call_with_frames_removed   File "C:\Python\64-bit\3.3\lib\tokenize.py", line 28, in <module>   File
"C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in
_find_and_load   File "C:\Python\64-bit\3.3\lib\importlib\_bootstrap.py", line 1522, in
_find_and_load_unlocked ImportError: No module named 're'

setup.py文件如下所示:

from cx_Freeze import setup, Executable

EXE = 'chat'
filename = EXE+'.py'

setup(
    name = EXE ,
    version = "0.1" ,
    description = "" ,
    executables = [Executable(filename)] ,
    )

我跑去编译的命令是:

python.exe setup.py build

2 个答案:

答案 0 :(得分:1)

尝试在python脚本中导入模块re。我不知道为什么,但是当我使用cxfreeze时,我还必须导入该模块才能使其正常工作。所以只需添加该行
import re
在运行cxfreeze之前,在代码的顶部,它应该完成这项工作。

答案 1 :(得分:1)

from cx_Freeze import setup, Executable

includes = ["sip","re","atexit"]
exe = Executable(script="chat.py",base="Win32GUI",icon = "images/icon.ico")
setup(options = {"chat": {"includes":includes}},executables = [exe])

包含此列表:包含进入设置非常重要