【转载】用cx_Freeze把Python代码打包成单个独立的exe可执行文件

来源:互联网 发布:马自达睿翼轮毂数据 编辑:程序博客网 时间:2024/06/05 13:26

链接:用cx_Freeze把Python代码打包成单个独立的exe可执行文件

【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件

背景

之前已经折腾过:

【记录】用PyInstaller把Python代码打包成单个独立的exe可执行文件

了,虽然已经,成功的,完美的,把对应的BlogsToWordpress打包成单个exe了。

但是貌似有人说cx_Freeze打包处理的文件会更小些,所以接着打算再去试试cx_Freeze。

cx_Freeze简介

将Python打包成可执行文件,cx_Freeze算是其中一个。

另外两个是py2exe和PyInstaller。

 

cx_Freeze的特点

其最大特点,目前看来,是只有cx_Freeze支持Python 3.x版本(py2exe和PyInstaller都暂不支持)。

 

下载cx_Freeze

找到

http://sourceforge.net/projects/cx-freeze/files/

中的

最新的

http://sourceforge.net/projects/cx-freeze/files/4.3.1/

下载和我当前环境:

win7 x64 + Python 2.7

所对应的:

cx_Freeze-4.3.1.win-amd64-py2.7.msi

得到688KB的

cx_Freeze-4.3.1.win-amd64-py2.7.msi

 

安装cx_Freeze

双击cx_Freeze-4.3.1.win-amd64-py2.7.msi去安装:

python 2.7 cx_Freeze 4.3.1 setup ui

found python path from reg

install cs_Freeze

然后就完成了。

 

使用cx_Freeze去打包exe

1.想去官网:

cx-freeze.sourceforge.net

找文档,结果很悲催的,此刻打不开。。。

2.找到一个readme:

http://python.net/crew/atuining/cx_Freeze/README.txt

然后去cmd中运行

FreezePython –help

结果都失败了:

?
1
2
3
4
5
6
7
8
9
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cs_Freeze>FreezePython --help
'FreezePython'is not recognized as an internal or external command,
operable program or batch file.
 
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cs_Freeze>FreezePython.py --help
'FreezePython.py'is not recognized as an internal or external command,
operable program or batch file.
 
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cs_Freeze>

3.继续找参考资料。

在安装目录中:

D:\tmp\dev_install_root\Python27_x64\Lib\site-packages\cx_Freeze

也没有找到相关文档。

4.后来终于找到之前就看到过的这个:

Welcome to cx_Freeze’s documentation!

cx_Freeze使用方法简介

cx_Freeze的三种用法

按照教程说法,cx_Freeze有三种用法:

  • 使用内含的cxfreeze script:用于简单的python脚本
  • 创建distutils setup script:用于稍微复杂的Python脚本,或为以后预留一定的配置
  • 直接使用cx_Freeze内部相关的类和模块:用于很复杂的Python脚本,或用于扩展,嵌入

 

cx_Freeze可生成三种可执行文件

产生的可执行文件,也有三种:

  • 把脚本用zip压缩成可执行文件:早期的cx_Freeze只支持此种单一方法
  • 创建出一个私有的zip压缩文件,但是文件名和前者一样,且以.zip结尾
  • 创建一个名为library.zip的压缩文件,把所有的模块都放到此文件里面:默认使用此种方法

后两种方法,对于Linux下面的RPM包,是必须要有的过程。

 

生成单一可执行文件的方法

cx_Freeze默认情况下,是会生成,一个可执行文件,加上一堆运行所需的(.dll或.so等)库文件。

如果想要生成单一的可执行文件:

  • Windows下的exe:使用(方法2的)setup script,且加上参数bdist_msi
    • 更高的打包,可使用:Inno Setup
  • Mac下的dmg:使用(方法2的)setup script,且加上参数bdist_dmg

 

针对Windows要注意的

Windows下的Python 2.6+,需要Microsoft Visual C++ 2008 Redistributable Package

cx_Freeze目前策略是,不自动拷贝相关所依赖的dll库文件。

关于其所说的:

C:\WINDOWS\WinSxS\Manifests\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375.manifest

C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375\msvcm90.dll

C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375\msvcp90.dll

C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375\msvcr90.dll

自己此处win7 x64中只找到:

C:\Windows\winsxs\Manifests\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91.manifest

C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91\msvcm90.dll

C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91\msvcp90.dll

C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91\msvcr90.dll

不过,应该是一样可以用的。

另外,也看到了,与这些文件对应的,还有些是针对x64的,wow64之类的。

估计是用于发布x64版本的可执行文件时,需要用到。

此处,顺便贴上

C:\Windows\winsxs\Manifests\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91.manifest

的内容

?
1
2
3
4
5
6
<?xmlversion="1.0"encoding="UTF-8"standalone="yes"?>
<assemblyxmlns="urn:schemas-microsoft-com:asm.v1"manifestVersion="1.0">
    <noInheritable></noInheritable>
    <assemblyIdentitytype="win32"name="Microsoft.VC90.CRT"version="9.0.21022.8"processorArchitecture="x86"publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    <filename="msvcr90.dll"hashalg="SHA1"hash="e0dcdcbfcb452747da530fae6b000d47c8674671"><asmv2:hashxmlns:asmv2="urn:schemas-microsoft-com:asm.v2"xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:TransformAlgorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethodAlgorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>KSaO8M0iCtPF6YEr79P1dZsnomY=</dsig:DigestValue></asmv2:hash></file> <filename="msvcp90.dll"hashalg="SHA1"hash="81efe890e4ef2615c0bb4dda7b94bea177c86ebd"><asmv2:hashxmlns:asmv2="urn:schemas-microsoft-com:asm.v2"xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:TransformAlgorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethodAlgorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>ojDmTgpYMFRKJYkPcM6ckpYkWUU=</dsig:DigestValue></asmv2:hash></file> <filename="msvcm90.dll"hashalg="SHA1"hash="5470081b336abd7b82c6387567a661a729483b04"><asmv2:hashxmlns:asmv2="urn:schemas-microsoft-com:asm.v2"xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:TransformAlgorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethodAlgorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>tVogb8kezDre2mXShlIqpp8ErIg=</dsig:DigestValue></asmv2:hash></file>
</assembly>

 

cx_Freeze中的distutils setup script的方法去生成可执行文件

1.参考:

distutils setup script

https://bitbucket.org/anthony_tuininga/cx_freeze/src

中的示例代码:

https://bitbucket.org/anthony_tuininga/cx_freeze/src/8913025af703028dfa7cc019c482be920f491dba/samples?at=default

去试试。

创建了一个:

D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cs_Freeze\setup.py

内容如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Name:        【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件
# Purpose:      http://www.crifan.com/use_cx_freeze_to_package_python_to_single_executable_exe
# Author:       Crifan Li
#
# Created:      06/01/2013
# Copyright:    (c) Crifan Li 2013
# Licence:      www.crifan.com
#-------------------------------------------------------------------------------
 
importsys;
fromcx_Freeze importsetup, Executable;
 
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options={
    "packages" : ["os"],
    #"includes": ["PIL"],
    "path"     : "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan\blogModules,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty\chardet,",
    "icon"     : "../../BlogsToWordpress\BlogsToWordpress.ico",
     
};
 
# GUI applications require a different base on Windows (the default is for a
# console application).
base=None
ifsys.platform =="win32":
    base="Win32GUI"
 
setup(  name ="BlogsToWordpress",
        version="16.8",
        description=u"将百度空间(新版和旧版),网易163,新浪sina,QQ空间,人人网,CSDN,搜狐Sohu,博客大巴Blogbus,天涯博客,点点轻博客等博客搬家到WordPress",
        options={"build_exe": build_exe_options},
        executables=[Executable("../../BlogsToWordpress/BlogsToWordpress.py", base=base)])

其中:

  • 此处故意没有把所有的模块都加到packages,否则单独一个个拷贝模块,也就累死了。看看脚本能否自动添加进去;

试试运行结果,结果出错:

ImportError: No module named ‘traceback’

详见:

【已解决】Python中通过cx_Freeze去打包exe出错:ImportError: No module named ‘traceback’

果然不够智能和好用啊。。。

2.最后,是如下配置:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Name:        【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件
# Purpose:      http://www.crifan.com/use_cx_freeze_to_package_python_to_single_executable_exe
# Author:       Crifan Li
#
# Created:      06/01/2013
# Copyright:    (c) Crifan Li 2013
# Licence:      www.crifan.com
#-------------------------------------------------------------------------------
 
# import sys;
# import traceback;
fromcx_Freeze importsetup, Executable;
 
# # Dependencies are automatically detected, but it might need fine tuning.
# build_exe_options = {
    # "packages"  : ["os"],
    # "includes" : [
        # "PIL",
        # #"traceback",
    # ],
    # "path"      : "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan\blogModules,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty\chardet,",
    # "icon"      : "../../BlogsToWordpress\BlogsToWordpress.ico",
     
# };
 
# 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 ="BlogsToWordpress",
        version="16.8",
        description=u"将百度空间(新版和旧版),网易163,新浪sina,QQ空间,人人网,CSDN,搜狐Sohu,博客大巴Blogbus,天涯博客,点点轻博客等博客搬家到WordPress",
        #options = {"build_exe": build_exe_options},
        #executables = [Executable("..\BlogsToWordpress\BlogsToWordpress.py", base=base)])
        executables=[Executable("..\BlogsToWordpress\BlogsToWordpress.py")])

然后运行正常:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>setup.py bdist_msi
running bdist_msi
running build
running build_exe
creating directory build\exe.win-amd64-2.7
copying D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.win-amd64-2.7\BlogsToWordpress.exe
copying C:\Windows\system32\python27.dll -> build\exe.win-amd64-2.7\python27.dll
Stamped: build\exe.win-amd64-2.7\BlogsToWordpress.exe
writing zip filebuild\exe.win-amd64-2.7\library.zip
 
  Name                      File
  ----                      ----
m BUILD_CONSTANTS
m StringIO
m UserDict
m __builtin__
m __future__                D:\tmp\dev_install_root\Python27_x64\lib\__future__.py
m __main__
m _abcoll
m _bisect
m _codecs
m _codecs_cn
m _codecs_hk
m _codecs_iso2022
m _codecs_jp
m _codecs_kr
m _codecs_tw
m _collections
m _functools
m _hashlib                  D:\tmp\dev_install_root\Python27_x64\DLLs\_hashlib.pyd
m _heapq
m _locale
m _md5
m _multibytecodec
m _random
m _sha
m _sha256
m _sha512
m _socket                   D:\tmp\dev_install_root\Python27_x64\DLLs\_socket.pyd
m _sre
m _ssl                      D:\tmp\dev_install_root\Python27_x64\DLLs\_ssl.pyd
m _strptime                 D:\tmp\dev_install_root\Python27_x64\lib\_strptime.py
m _struct
m _threading_local          D:\tmp\dev_install_root\Python27_x64\lib\_threading_local.py
m _warnings
m _weakref
m _weakrefset
m _winreg
m abc
m array
m atexit                    D:\tmp\dev_install_root\Python27_x64\lib\atexit.py
m base64
m bdb                       D:\tmp\dev_install_root\Python27_x64\lib\bdb.py
m binascii
m bisect                    D:\tmp\dev_install_root\Python27_x64\lib\bisect.py
m blogstowordpress__main__  ..\BlogsToWordpress\BlogsToWordpress.py
m bz2                       D:\tmp\dev_install_root\Python27_x64\DLLs\bz2.pyd
m cPickle
m cStringIO
m calendar                  D:\tmp\dev_install_root\Python27_x64\lib\calendar.py
m cmd                       D:\tmp\dev_install_root\Python27_x64\lib\cmd.py
m codecs
m collections               D:\tmp\dev_install_root\Python27_x64\lib\collections.py
m copy
m copy_reg
m cx_Freeze__init__         D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\initscripts\Console.py
m datetime
m difflib                   D:\tmp\dev_install_root\Python27_x64\lib\difflib.py
m dis                       D:\tmp\dev_install_root\Python27_x64\lib\dis.py
m doctest                   D:\tmp\dev_install_root\Python27_x64\lib\doctest.py
m dummy_thread              D:\tmp\dev_install_root\Python27_x64\lib\dummy_thread.py
P email                     D:\tmp\dev_install_root\Python27_x64\lib\email\__init__.py
m email._parseaddr          D:\tmp\dev_install_root\Python27_x64\lib\email\_parseaddr.py
m email.base64mime          D:\tmp\dev_install_root\Python27_x64\lib\email\base64mime.py
m email.charset             D:\tmp\dev_install_root\Python27_x64\lib\email\charset.py
m email.encoders            D:\tmp\dev_install_root\Python27_x64\lib\email\encoders.py
m email.errors              D:\tmp\dev_install_root\Python27_x64\lib\email\errors.py
m email.feedparser          D:\tmp\dev_install_root\Python27_x64\lib\email\feedparser.py
m email.generator           D:\tmp\dev_install_root\Python27_x64\lib\email\generator.py
m email.header              D:\tmp\dev_install_root\Python27_x64\lib\email\header.py
m email.iterators           D:\tmp\dev_install_root\Python27_x64\lib\email\iterators.py
m email.message             D:\tmp\dev_install_root\Python27_x64\lib\email\message.py
P email.mime                D:\tmp\dev_install_root\Python27_x64\lib\email\mime\__init__.py
m email.parser              D:\tmp\dev_install_root\Python27_x64\lib\email\parser.py
m email.quoprimime          D:\tmp\dev_install_root\Python27_x64\lib\email\quoprimime.py
m email.utils               D:\tmp\dev_install_root\Python27_x64\lib\email\utils.py
P encodings
m encodings.aliases
m encodings.ascii
m encodings.base64_codec
m encodings.big5
m encodings.big5hkscs
m encodings.bz2_codec
m encodings.charmap
m encodings.cp037
m encodings.cp1006
m encodings.cp1026
m encodings.cp1140
m encodings.cp1250
m encodings.cp1251
m encodings.cp1252
m encodings.cp1253
m encodings.cp1254
m encodings.cp1255
m encodings.cp1256
m encodings.cp1257
m encodings.cp1258
m encodings.cp424
m encodings.cp437
m encodings.cp500
m encodings.cp720
m encodings.cp737
m encodings.cp775
m encodings.cp850
m encodings.cp852
m encodings.cp855
m encodings.cp856
m encodings.cp857
m encodings.cp858
m encodings.cp860
m encodings.cp861
m encodings.cp862
m encodings.cp863
m encodings.cp864
m encodings.cp865
m encodings.cp866
m encodings.cp869
m encodings.cp874
m encodings.cp875
m encodings.cp932
m encodings.cp949
m encodings.cp950
m encodings.euc_jis_2004
m encodings.euc_jisx0213
m encodings.euc_jp
m encodings.euc_kr
m encodings.gb18030
m encodings.gb2312
m encodings.gbk
m encodings.hex_codec
m encodings.hp_roman8
m encodings.hz
m encodings.idna
m encodings.iso2022_jp
m encodings.iso2022_jp_1
m encodings.iso2022_jp_2
m encodings.iso2022_jp_2004
m encodings.iso2022_jp_3
m encodings.iso2022_jp_ext
m encodings.iso2022_kr
m encodings.iso8859_1
m encodings.iso8859_10
m encodings.iso8859_11
m encodings.iso8859_13
m encodings.iso8859_14
m encodings.iso8859_15
m encodings.iso8859_16
m encodings.iso8859_2
m encodings.iso8859_3
m encodings.iso8859_4
m encodings.iso8859_5
m encodings.iso8859_6
m encodings.iso8859_7
m encodings.iso8859_8
m encodings.iso8859_9
m encodings.johab
m encodings.koi8_r
m encodings.koi8_u
m encodings.latin_1
m encodings.mac_arabic
m encodings.mac_centeuro
m encodings.mac_croatian
m encodings.mac_cyrillic
m encodings.mac_farsi
m encodings.mac_greek
m encodings.mac_iceland
m encodings.mac_latin2
m encodings.mac_roman
m encodings.mac_romanian
m encodings.mac_turkish
m encodings.mbcs
m encodings.palmos
m encodings.ptcp154
m encodings.punycode
m encodings.quopri_codec
m encodings.raw_unicode_escape
m encodings.rot_13
m encodings.shift_jis
m encodings.shift_jis_2004
m encodings.shift_jisx0213
m encodings.string_escape
m encodings.tis_620
m encodings.undefined
m encodings.unicode_escape
m encodings.unicode_internal
m encodings.utf_16
m encodings.utf_16_be
m encodings.utf_16_le
m encodings.utf_32
m encodings.utf_32_be
m encodings.utf_32_le
m encodings.utf_7
m encodings.utf_8
m encodings.utf_8_sig
m encodings.uu_codec
m encodings.zlib_codec
m errno
m exceptions
m fnmatch                   D:\tmp\dev_install_root\Python27_x64\lib\fnmatch.py
m ftplib                    D:\tmp\dev_install_root\Python27_x64\lib\ftplib.py
m functools                 D:\tmp\dev_install_root\Python27_x64\lib\functools.py
m genericpath
m getopt                    D:\tmp\dev_install_root\Python27_x64\lib\getopt.py
m getpass                   D:\tmp\dev_install_root\Python27_x64\lib\getpass.py
m gettext                   D:\tmp\dev_install_root\Python27_x64\lib\gettext.py
m hashlib                   D:\tmp\dev_install_root\Python27_x64\lib\hashlib.py
m heapq                     D:\tmp\dev_install_root\Python27_x64\lib\heapq.py
m httplib                   D:\tmp\dev_install_root\Python27_x64\lib\httplib.py
m imp
m inspect                   D:\tmp\dev_install_root\Python27_x64\lib\inspect.py
m itertools
m keyword                   D:\tmp\dev_install_root\Python27_x64\lib\keyword.py
m linecache
m locale                    D:\tmp\dev_install_root\Python27_x64\lib\locale.py
P logging                   D:\tmp\dev_install_root\Python27_x64\lib\logging\__init__.py
m math
m mimetools                 D:\tmp\dev_install_root\Python27_x64\lib\mimetools.py
m mimetypes                 D:\tmp\dev_install_root\Python27_x64\lib\mimetypes.py
m msvcrt
m nt
m ntpath
m nturl2path                D:\tmp\dev_install_root\Python27_x64\lib\nturl2path.py
m opcode                    D:\tmp\dev_install_root\Python27_x64\lib\opcode.py
m operator
m optparse                  D:\tmp\dev_install_root\Python27_x64\lib\optparse.py
m os
m pdb                       D:\tmp\dev_install_root\Python27_x64\lib\pdb.py
m platform                  D:\tmp\dev_install_root\Python27_x64\lib\platform.py
m plistlib                  D:\tmp\dev_install_root\Python27_x64\lib\plistlib.py
m posixpath
m pprint                    D:\tmp\dev_install_root\Python27_x64\lib\pprint.py
m pyexpat                   D:\tmp\dev_install_root\Python27_x64\DLLs\pyexpat.pyd
m pywintypes                C:\Windows\system32\pywintypes27.dll
m quopri
m random                    D:\tmp\dev_install_root\Python27_x64\lib\random.py
m re                        D:\tmp\dev_install_root\Python27_x64\lib\re.py
m repr
m rfc822                    D:\tmp\dev_install_root\Python27_x64\lib\rfc822.py
m shlex                     D:\tmp\dev_install_root\Python27_x64\lib\shlex.py
m signal
m socket                    D:\tmp\dev_install_root\Python27_x64\lib\socket.py
m sre_compile               D:\tmp\dev_install_root\Python27_x64\lib\sre_compile.py
m sre_constants             D:\tmp\dev_install_root\Python27_x64\lib\sre_constants.py
m sre_parse                 D:\tmp\dev_install_root\Python27_x64\lib\sre_parse.py
m ssl                       D:\tmp\dev_install_root\Python27_x64\lib\ssl.py
m stat
m string
m stringprep
m strop
m struct
m sys
m tempfile                  D:\tmp\dev_install_root\Python27_x64\lib\tempfile.py
m textwrap                  D:\tmp\dev_install_root\Python27_x64\lib\textwrap.py
m thread
m threading                 D:\tmp\dev_install_root\Python27_x64\lib\threading.py
mtime
m token                     D:\tmp\dev_install_root\Python27_x64\lib\token.py
m tokenize                  D:\tmp\dev_install_root\Python27_x64\lib\tokenize.py
m traceback
m types
m unicodedata               D:\tmp\dev_install_root\Python27_x64\DLLs\unicodedata.pyd
P unittest                  D:\tmp\dev_install_root\Python27_x64\lib\unittest\__init__.py
m unittest.case            D:\tmp\dev_install_root\Python27_x64\lib\unittest\case.py
m unittest.loader           D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.py
m unittest.main             D:\tmp\dev_install_root\Python27_x64\lib\unittest\main.py
m unittest.result           D:\tmp\dev_install_root\Python27_x64\lib\unittest\result.py
m unittest.runner           D:\tmp\dev_install_root\Python27_x64\lib\unittest\runner.py
m unittest.signals          D:\tmp\dev_install_root\Python27_x64\lib\unittest\signals.py
m unittest.suite            D:\tmp\dev_install_root\Python27_x64\lib\unittest\suite.py
m unittest.util             D:\tmp\dev_install_root\Python27_x64\lib\unittest\util.py
m urllib                    D:\tmp\dev_install_root\Python27_x64\lib\urllib.py
m urlparse                  D:\tmp\dev_install_root\Python27_x64\lib\urlparse.py
m uu                        D:\tmp\dev_install_root\Python27_x64\lib\uu.py
m warnings
m weakref
m win32api                  D:\tmp\dev_install_root\Python27_x64\lib\site-packages\win32\win32api.pyd
m win32con                  D:\tmp\dev_install_root\Python27_x64\lib\site-packages\win32\lib\win32con.py
m win32pipe                 D:\tmp\dev_install_root\Python27_x64\lib\site-packages\win32\win32pipe.pyd
P xml                       D:\tmp\dev_install_root\Python27_x64\lib\xml\__init__.py
P xml.parsers               D:\tmp\dev_install_root\Python27_x64\lib\xml\parsers\__init__.py
m xml.parsers.expat         D:\tmp\dev_install_root\Python27_x64\lib\xml\parsers\expat.py
P xml.sax                   D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\__init__.py
m xml.sax._exceptions       D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\_exceptions.py
m xml.sax.expatreader       D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\expatreader.py
m xml.sax.handler           D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\handler.py
m xml.sax.saxutils          D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\saxutils.py
m xml.sax.xmlreader         D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\xmlreader.py
m zipimport
m zlib
 
Missing modules:
? BlogBaidu imported from blogstowordpress__main__
? BlogBlogbus imported from blogstowordpress__main__
? BlogCsdn imported from blogstowordpress__main__
? BlogDiandian imported from blogstowordpress__main__
? BlogNetease imported from blogstowordpress__main__
? BlogQQ imported from blogstowordpress__main__
? BlogRenren imported from blogstowordpress__main__
? BlogSina imported from blogstowordpress__main__
? BlogSohu imported from blogstowordpress__main__
? BlogTianya imported from blogstowordpress__main__
? crifanLib imported from blogstowordpress__main__
 
copying D:\tmp\dev_install_root\Python27_x64\DLLs\_hashlib.pyd -> build\exe.win-amd64-2.7\_hashlib.pyd
copying D:\tmp\dev_install_root\Python27_x64\DLLs\_socket.pyd -> build\exe.win-amd64-2.7\_socket.pyd
copying D:\tmp\dev_install_root\Python27_x64\DLLs\_ssl.pyd -> build\exe.win-amd64-2.7\_ssl.pyd
copying D:\tmp\dev_install_root\Python27_x64\DLLs\bz2.pyd -> build\exe.win-amd64-2.7\bz2.pyd
copying D:\tmp\dev_install_root\Python27_x64\DLLs\pyexpat.pyd -> build\exe.win-amd64-2.7\pyexpat.pyd
copying C:\Windows\system32\pywintypes27.dll -> build\exe.win-amd64-2.7\pywintypes27.dll
copying D:\tmp\dev_install_root\Python27_x64\DLLs\unicodedata.pyd -> build\exe.win-amd64-2.7\unicodedata.pyd
copying D:\tmp\dev_install_root\Python27_x64\lib\site-packages\win32\win32api.pyd -> build\exe.win-amd64-2.7\win32api.pyd
copying D:\tmp\dev_install_root\Python27_x64\lib\site-packages\win32\win32pipe.pyd -> build\exe.win-amd64-2.7\win32pipe.pyd
installing to build\bdist.win-amd64\msi
running install_exe
creating build\bdist.win-amd64
creating build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\BlogsToWordpress.exe -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\bz2.pyd -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\library.zip -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\pyexpat.pyd -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\python27.dll -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\pywintypes27.dll -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\unicodedata.pyd -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\win32api.pyd -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\win32pipe.pyd -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\_hashlib.pyd -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\_socket.pyd -> build\bdist.win-amd64\msi
copying build\exe.win-amd64-2.7\_ssl.pyd -> build\bdist.win-amd64\msi
creating dist
removing'build\bdist.win-amd64\msi'(and everything under it)
 
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>setup.py bdist_msi

生成的结果是:

和setup.py同目录下,生成dist和build:

with setup.py gen build and dist

build\exe.win-amd64-2.7下面,生成对应的:

exe文件,相关的一堆库文件和pyd

gen exe win amd64 2.7 and dll

dist下面生成对应的msi文件:

BlogsToWordpress-16.8-amd64.msi

BlogsToWordpress-16.8-amd64 msi file

 

3.此时,才明白,此处,使用

setup.py bdist_msi

是生成的installer,而不是单个的,独立的exe。。。。

接着就是想办法去生成,独立的,单个的,exe可执行文件。

4.先不去弄了。

因为先去试试exe是否可以正常运行,结果果然不能:

?
1
2
3
4
5
6
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze\build\exe.win-amd64-2.7>BlogsToWordpress.exe
Traceback (most recent call last):
  File"D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in<module>
    execcode inm.__dict__
  File"..\BlogsToWordpress\BlogsToWordpress.py", line 127, in<module>
ImportError: No module named crifanLib

很明显,缺少对应的库。

所以,还是要先去添加对应的path。

所以改为:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Name:        【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件
# Purpose:      http://www.crifan.com/use_cx_freeze_to_package_python_to_single_executable_exe
# Author:       Crifan Li
#
# Created:      06/01/2013
# Copyright:    (c) Crifan Li 2013
# Licence:      www.crifan.com
#-------------------------------------------------------------------------------
 
# import sys;
# import traceback;
fromcx_Freeze importsetup, Executable;
 
# # Dependencies are automatically detected, but it might need fine tuning.
build_exe_options={
    # "packages"  : ["os"],
    # "includes" : [
        # "PIL",
        # #"traceback",
    # ],
    "path"     : "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan\blogModules,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty,D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty\chardet,",
    # "icon"      : "../../BlogsToWordpress\BlogsToWordpress.ico",
};
 
# 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 ="BlogsToWordpress",
        version="16.8",
        description=u"将百度空间(新版和旧版),网易163,新浪sina,QQ空间,人人网,CSDN,搜狐Sohu,博客大巴Blogbus,天涯博客,点点轻博客等博客搬家到WordPress",
        options={"build_exe": build_exe_options},
        #executables = [Executable("..\BlogsToWordpress\BlogsToWordpress.py", base=base)])
        executables=[Executable("..\BlogsToWordpress\BlogsToWordpress.py")])

运行结果是:

结果就出现了,上面的那个:

ImportError: No module named ‘traceback’

错误。

很明显,此处就是setup的options,无法识别所导致的。

5.然后去运行了build:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>setup.py build
running build
running build_exe
creating directory build\exe.win-amd64-2.7
copying D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.win-amd64-2.7\BlogsToWordpress.exe
copying C:\Windows\system32\python27.dll -> build\exe.win-amd64-2.7\python27.dll
Stamped: build\exe.win-amd64-2.7\BlogsToWordpress.exe
writing zip filebuild\exe.win-amd64-2.7\library.zip
 
  Name                      File
  ----                      ----
m BUILD_CONSTANTS
m StringIO
m UserDict
m __builtin__
m __future__                D:\tmp\dev_install_root\Python27_x64\lib\__future__.py
m __main__
m _abcoll
m _bisect
m _codecs
m _codecs_cn
m _codecs_hk
m _codecs_iso2022
m _codecs_jp
m _codecs_kr
m _codecs_tw
m _collections
m _functools
m _hashlib                  D:\tmp\dev_install_root\Python27_x64\DLLs\_hashlib.pyd
m _heapq
m _locale
m _md5
m _multibytecodec
m _random
m _sha
m _sha256
m _sha512
m _socket                   D:\tmp\dev_install_root\Python27_x64\DLLs\_socket.pyd
m _sre
m _ssl                      D:\tmp\dev_install_root\Python27_x64\DLLs\_ssl.pyd
m _strptime                 D:\tmp\dev_install_root\Python27_x64\lib\_strptime.py
m _struct
m _threading_local          D:\tmp\dev_install_root\Python27_x64\lib\_threading_local.py
m _warnings
m _weakref
m _weakrefset
m _winreg
m abc
m array
m atexit                    D:\tmp\dev_install_root\Python27_x64\lib\atexit.py
m base64
m bdb                       D:\tmp\dev_install_root\Python27_x64\lib\bdb.py
m binascii
m bisect                    D:\tmp\dev_install_root\Python27_x64\lib\bisect.py
m blogstowordpress__main__  ..\BlogsToWordpress\BlogsToWordpress.py
m bz2                       D:\tmp\dev_install_root\Python27_x64\DLLs\bz2.pyd
m cPickle
m cStringIO
m calendar                  D:\tmp\dev_install_root\Python27_x64\lib\calendar.py
m cmd                       D:\tmp\dev_install_root\Python27_x64\lib\cmd.py
m codecs
m collections               D:\tmp\dev_install_root\Python27_x64\lib\collections.py
m copy
m copy_reg
m cx_Freeze__init__         D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\initscripts\Console.py
m datetime
m difflib                   D:\tmp\dev_install_root\Python27_x64\lib\difflib.py
m dis                       D:\tmp\dev_install_root\Python27_x64\lib\dis.py
m doctest                   D:\tmp\dev_install_root\Python27_x64\lib\doctest.py
m dummy_thread              D:\tmp\dev_install_root\Python27_x64\lib\dummy_thread.py
P email                     D:\tmp\dev_install_root\Python27_x64\lib\email\__init__.py
m email._parseaddr          D:\tmp\dev_install_root\Python27_x64\lib\email\_parseaddr.py
m email.base64mime          D:\tmp\dev_install_root\Python27_x64\lib\email\base64mime.py
m email.charset             D:\tmp\dev_install_root\Python27_x64\lib\email\charset.py
m email.encoders            D:\tmp\dev_install_root\Python27_x64\lib\email\encoders.py
m email.errors              D:\tmp\dev_install_root\Python27_x64\lib\email\errors.py
m email.feedparser          D:\tmp\dev_install_root\Python27_x64\lib\email\feedparser.py
m email.generator           D:\tmp\dev_install_root\Python27_x64\lib\email\generator.py
m email.header              D:\tmp\dev_install_root\Python27_x64\lib\email\header.py
m email.iterators           D:\tmp\dev_install_root\Python27_x64\lib\email\iterators.py
m email.message             D:\tmp\dev_install_root\Python27_x64\lib\email\message.py
P email.mime                D:\tmp\dev_install_root\Python27_x64\lib\email\mime\__init__.py
m email.parser              D:\tmp\dev_install_root\Python27_x64\lib\email\parser.py
m email.quoprimime          D:\tmp\dev_install_root\Python27_x64\lib\email\quoprimime.py
m email.utils               D:\tmp\dev_install_root\Python27_x64\lib\email\utils.py
P encodings
m encodings.aliases
m encodings.ascii
m encodings.base64_codec
m encodings.big5
m encodings.big5hkscs
m encodings.bz2_codec
m encodings.charmap
m encodings.cp037
m encodings.cp1006
m encodings.cp1026
m encodings.cp1140
m encodings.cp1250
m encodings.cp1251
m encodings.cp1252
m encodings.cp1253
m encodings.cp1254
m encodings.cp1255
m encodings.cp1256
m encodings.cp1257
m encodings.cp1258
m encodings.cp424
m encodings.cp437
m encodings.cp500
m encodings.cp720
m encodings.cp737
m encodings.cp775
m encodings.cp850
m encodings.cp852
m encodings.cp855
m encodings.cp856
m encodings.cp857
m encodings.cp858
m encodings.cp860
m encodings.cp861
m encodings.cp862
m encodings.cp863
m encodings.cp864
m encodings.cp865
m encodings.cp866
m encodings.cp869
m encodings.cp874
m encodings.cp875
m encodings.cp932
m encodings.cp949
m encodings.cp950
m encodings.euc_jis_2004
m encodings.euc_jisx0213
m encodings.euc_jp
m encodings.euc_kr
m encodings.gb18030
m encodings.gb2312
m encodings.gbk
m encodings.hex_codec
m encodings.hp_roman8
m encodings.hz
m encodings.idna
m encodings.iso2022_jp
m encodings.iso2022_jp_1
m encodings.iso2022_jp_2
m encodings.iso2022_jp_2004
m encodings.iso2022_jp_3
m encodings.iso2022_jp_ext
m encodings.iso2022_kr
m encodings.iso8859_1
m encodings.iso8859_10
m encodings.iso8859_11
m encodings.iso8859_13
m encodings.iso8859_14
m encodings.iso8859_15
m encodings.iso8859_16
m encodings.iso8859_2
m encodings.iso8859_3
m encodings.iso8859_4
m encodings.iso8859_5
m encodings.iso8859_6
m encodings.iso8859_7
m encodings.iso8859_8
m encodings.iso8859_9
m encodings.johab
m encodings.koi8_r
m encodings.koi8_u
m encodings.latin_1
m encodings.mac_arabic
m encodings.mac_centeuro
m encodings.mac_croatian
m encodings.mac_cyrillic
m encodings.mac_farsi
m encodings.mac_greek
m encodings.mac_iceland
m encodings.mac_latin2
m encodings.mac_roman
m encodings.mac_romanian
m encodings.mac_turkish
m encodings.mbcs
m encodings.palmos
m encodings.ptcp154
m encodings.punycode
m encodings.quopri_codec
m encodings.raw_unicode_escape
m encodings.rot_13
m encodings.shift_jis
m encodings.shift_jis_2004
m encodings.shift_jisx0213
m encodings.string_escape
m encodings.tis_620
m encodings.undefined
m encodings.unicode_escape
m encodings.unicode_internal
m encodings.utf_16
m encodings.utf_16_be
m encodings.utf_16_le
m encodings.utf_32
m encodings.utf_32_be
m encodings.utf_32_le
m encodings.utf_7
m encodings.utf_8
m encodings.utf_8_sig
m encodings.uu_codec
m encodings.zlib_codec
m errno
m exceptions
m fnmatch                   D:\tmp\dev_install_root\Python27_x64\lib\fnmatch.py
m ftplib                    D:\tmp\dev_install_root\Python27_x64\lib\ftplib.py
m functools                 D:\tmp\dev_install_root\Python27_x64\lib\functools.py
m genericpath
m getopt                    D:\tmp\dev_install_root\Python27_x64\lib\getopt.py
m getpass                   D:\tmp\dev_install_root\Python27_x64\lib\getpass.py
m gettext                   D:\tmp\dev_install_root\Python27_x64\lib\gettext.py
m hashlib                   D:\tmp\dev_install_root\Python27_x64\lib\hashlib.py
m heapq                     D:\tmp\dev_install_root\Python27_x64\lib\heapq.py
m httplib                   D:\tmp\dev_install_root\Python27_x64\lib\httplib.py
m imp
m inspect                   D:\tmp\dev_install_root\Python27_x64\lib\inspect.py
m itertools
m keyword                   D:\tmp\dev_install_root\Python27_x64\lib\keyword.py
m linecache
m locale                    D:\tmp\dev_install_root\Python27_x64\lib\locale.py
P logging                   D:\tmp\dev_install_root\Python27_x64\lib\logging\__init__.py
m math
m mimetools                 D:\tmp\dev_install_root\Python27_x64\lib\mimetools.py
m mimetypes                 D:\tmp\dev_install_root\Python27_x64\lib\mimetypes.py
m msvcrt
m nt
m ntpath
m nturl2path                D:\tmp\dev_install_root\Python27_x64\lib\nturl2path.py
m opcode                    D:\tmp\dev_install_root\Python27_x64\lib\opcode.py
m operator
m optparse                  D:\tmp\dev_install_root\Python27_x64\lib\optparse.py
m os
m pdb                       D:\tmp\dev_install_root\Python27_x64\lib\pdb.py
m platform                  D:\tmp\dev_install_root\Python27_x64\lib\platform.py
m plistlib                  D:\tmp\dev_install_root\Python27_x64\lib\plistlib.py
m posixpath
m pprint                    D:\tmp\dev_install_root\Python27_x64\lib\pprint.py
m pyexpat                   D:\tmp\dev_install_root\Python27_x64\DLLs\pyexpat.pyd
m pywintypes                C:\Windows\system32\pywintypes27.dll
m quopri
m random                    D:\tmp\dev_install_root\Python27_x64\lib\random.py
m re                        D:\tmp\dev_install_root\Python27_x64\lib\re.py
m repr
m rfc822                    D:\tmp\dev_install_root\Python27_x64\lib\rfc822.py
m shlex                     D:\tmp\dev_install_root\Python27_x64\lib\shlex.py
m signal
m socket                    D:\tmp\dev_install_root\Python27_x64\lib\socket.py
m sre_compile               D:\tmp\dev_install_root\Python27_x64\lib\sre_compile.py
m sre_constants             D:\tmp\dev_install_root\Python27_x64\lib\sre_constants.py
m sre_parse                 D:\tmp\dev_install_root\Python27_x64\lib\sre_parse.py
m ssl                       D:\tmp\dev_install_root\Python27_x64\lib\ssl.py
m stat
m string
m stringprep
m strop
m struct
m sys
m tempfile                  D:\tmp\dev_install_root\Python27_x64\lib\tempfile.py
m textwrap                  D:\tmp\dev_install_root\Python27_x64\lib\textwrap.py
m thread
m threading                 D:\tmp\dev_install_root\Python27_x64\lib\threading.py
mtime
m token                     D:\tmp\dev_install_root\Python27_x64\lib\token.py
m tokenize                  D:\tmp\dev_install_root\Python27_x64\lib\tokenize.py
m traceback
m types
m unicodedata               D:\tmp\dev_install_root\Python27_x64\DLLs\unicodedata.pyd
P unittest                  D:\tmp\dev_install_root\Python27_x64\lib\unittest\__init__.py
m unittest.case            D:\tmp\dev_install_root\Python27_x64\lib\unittest\case.py
m unittest.loader           D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.py
m unittest.main             D:\tmp\dev_install_root\Python27_x64\lib\unittest\main.py
m unittest.result           D:\tmp\dev_install_root\Python27_x64\lib\unittest\result.py
m unittest.runner           D:\tmp\dev_install_root\Python27_x64\lib\unittest\runner.py
m unittest.signals          D:\tmp\dev_install_root\Python27_x64\lib\unittest\signals.py
m unittest.suite            D:\tmp\dev_install_root\Python27_x64\lib\unittest\suite.py
m unittest.util             D:\tmp\dev_install_root\Python27_x64\lib\unittest\util.py
m urllib                    D:\tmp\dev_install_root\Python27_x64\lib\urllib.py
m urlparse                  D:\tmp\dev_install_root\Python27_x64\lib\urlparse.py
m uu                        D:\tmp\dev_install_root\Python27_x64\lib\uu.py
m warnings
m weakref
m win32api                  D:\tmp\dev_install_root\Python27_x64\lib\site-packages\win32\win32api.pyd
m win32con                  D:\tmp\dev_install_root\Python27_x64\lib\site-packages\win32\lib\win32con.py
m win32pipe                 D:\tmp\dev_install_root\Python27_x64\lib\site-packages\win32\win32pipe.pyd
P xml                       D:\tmp\dev_install_root\Python27_x64\lib\xml\__init__.py
P xml.parsers               D:\tmp\dev_install_root\Python27_x64\lib\xml\parsers\__init__.py
m xml.parsers.expat         D:\tmp\dev_install_root\Python27_x64\lib\xml\parsers\expat.py
P xml.sax                   D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\__init__.py
m xml.sax._exceptions       D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\_exceptions.py
m xml.sax.expatreader       D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\expatreader.py
m xml.sax.handler           D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\handler.py
m xml.sax.saxutils          D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\saxutils.py
m xml.sax.xmlreader         D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\xmlreader.py
m zipimport
m zlib
 
Missing modules:
? BlogBaidu imported from blogstowordpress__main__
? BlogBlogbus imported from blogstowordpress__main__
? BlogCsdn imported from blogstowordpress__main__
? BlogDiandian imported from blogstowordpress__main__
? BlogNetease imported from blogstowordpress__main__
? BlogQQ imported from blogstowordpress__main__
? BlogRenren imported from blogstowordpress__main__
? BlogSina imported from blogstowordpress__main__
? BlogSohu imported from blogstowordpress__main__
? BlogTianya imported from blogstowordpress__main__
? crifanLib imported from blogstowordpress__main__
 
copying D:\tmp\dev_install_root\Python27_x64\DLLs\_hashlib.pyd -> build\exe.win-amd64-2.7\_hashlib.pyd
copying D:\tmp\dev_install_root\Python27_x64\DLLs\_socket.pyd -> build\exe.win-amd64-2.7\_socket.pyd
copying D:\tmp\dev_install_root\Python27_x64\DLLs\_ssl.pyd -> build\exe.win-amd64-2.7\_ssl.pyd
copying D:\tmp\dev_install_root\Python27_x64\DLLs\bz2.pyd -> build\exe.win-amd64-2.7\bz2.pyd
copying D:\tmp\dev_install_root\Python27_x64\DLLs\pyexpat.pyd -> build\exe.win-amd64-2.7\pyexpat.pyd
copying C:\Windows\system32\pywintypes27.dll -> build\exe.win-amd64-2.7\pywintypes27.dll
copying D:\tmp\dev_install_root\Python27_x64\DLLs\unicodedata.pyd -> build\exe.win-amd64-2.7\unicodedata.pyd
copying D:\tmp\dev_install_root\Python27_x64\lib\site-packages\win32\win32api.pyd -> build\exe.win-amd64-2.7\win32api.pyd
copying D:\tmp\dev_install_root\Python27_x64\lib\site-packages\win32\win32pipe.pyd -> build\exe.win-amd64-2.7\win32pipe.pyd
 
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>

然后发现了,对应的会生成

exe.win-amd64-2.7

极其下所有文件,即exe相关的所有文件。

6.因此也就很明显了:

setup.py bdist_msi

是在

setup.py build

的基础上,将其生成的exe和对应的库文件等内容,集成为对应的msi的installer。

7.但是,弄到现在为止,还是没有看到,有任何选项,是可以生成,独立的,单一的exe的。

且不说,即使生成exe加上库文件,也还是需要:

手动添加path便于搜索所依赖的库

仍需手动,一个个添加对应的库的名字。

8.所以,至此,虽然上述问题,可以花时间解决,但是都还是无法最终生成单一的exe,所以,直接放弃此cx_Freeze了。

和PyInstaller相比,可以叫做,极度的,不好用。

其唯一的相对的优势就是,支持Python 3.x。

 

总结

cx_Freeze,可以生成:

  • exe文件 + 运行时所依赖的其他多个(dll库等)文件
    • 但不是单一的,独立的,exe可执行文件
  • 单独的msi安装文件包
    • 比如:BlogsToWordpress-16.8-amd64.msi

和PyInstaller相比:

  • 缺点
    • 需要手动自己输入,所依赖的库的名字,而无法自动识别
      • 像我这里的项目,单是依赖的库,就N多个,如果需要手动输入,累都累屎了
    • 还需要添加对应的path,供其搜索依赖的库
      • 此处会出错解决上述的错误:ImportError: No module named ‘traceback’,目前懒得去解决了。
  • 优点
    • 支持Python 3.x

 

结论

如果是想要生成:

  • 单个的,独立的exe可执行文件
  • 或者
  • exe + 相关的dll库

等,都可以使用,极其方便好用的PyInstaller;

用法可参考:

【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件

 

如果是想要生成:

  • msi安装文件
  • 或者
  • 必须用到Python 3.x版本

那么再去用,相对来说非常不好用的,cx_Freeze。


0 0
原创粉丝点击