最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

Python crifan 11019浏览 0评论

【问题】

折腾:

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

的过程中,出错:

D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>setup.py bdist_msi
running bdist_msi
running build
running build_exe
Traceback (most recent call last):
  File "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze\setup.py", line 35, in <module>
    executables = [Executable("../../BlogsToWordpress/BlogsToWordpress.py", base=base)])
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\dist.py", line 365, in setup
    distutils.core.setup(**attrs)
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\windist.py", line 363, in run
    self.run_command('build')
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\command\build.py", line 127, in run
    self.run_command(cmd_name)
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\dist.py", line 235, in run
    freezer.Freeze()
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\freezer.py", line 570, in Freeze
    self.finder = self._GetModuleFinder()
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\freezer.py", line 318, in _GetModuleFinder
    argsSource.copyDependentFiles, compress = argsSource.compress)
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\finder.py", line 54, in __init__
    self._AddBaseModules()
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\finder.py", line 69, in _AddBaseModules
    self.IncludeModule("traceback")
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\finder.py", line 526, in IncludeModule
    namespace = namespace)
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\finder.py", line 274, in _ImportModule
    raise ImportError("No module named %r" % name)
ImportError: No module named 'traceback'

D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>

 

【解决过程】

1.参考:

exe error with cx_freeze

去把includes加上,变成:

#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Name:        【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件
# Purpose:      https://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;
from cx_Freeze import setup, 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
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)])

然后再去运行看看效果。

结果问题依旧。

2.把对应的traceback加进去:

    "includes" : [
        "PIL",
        "traceback",
    ],

再去运行看看,问题依旧。

3.参考:

cx_Freeze ImportError: cannot import name

去手动添加参数,结果也不识别:

D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>setup.py bdist_msi --include-modules traceback
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: option --include-modules not recognized

D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>setup.py bdist_msi --include-modules=traceback
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: option --include-modules not recognized

4.貌似需要另外去安装这个traceback模块啊。。。

这也太悲催,太不好用了。

5.网上找不到解决办法。

看来只能自己去看源代码了。。。

6.后来注意到,其中输出有:

executables = [Executable("../../BlogsToWordpress/BlogsToWordpress.py", base=base)])

然后去cmd下面,测试了一下:

D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>ls ..\BlogsToWordpress\BlogsToWordpress.py

发现自己多写了个..,所以,应该是:

#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Name:        【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件
# Purpose:      https://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;
from cx_Freeze import setup, 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)])

然后运行效果是,问题依旧:

D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>setup.py bdist_msi
running bdist_msi
running build
running build_exe
Traceback (most recent call last):
  File "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze\setup.py", line 38, in <module>
    executables = [Executable("..\BlogsToWordpress\BlogsToWordpress.py", base=base)])
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\dist.py", line 365, in setup
    distutils.core.setup(**attrs)
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\windist.py", line 363, in run
    self.run_command('build')
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\command\build.py", line 127, in run
    self.run_command(cmd_name)
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "D:\tmp\dev_install_root\Python27_x64\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\dist.py", line 235, in run
    freezer.Freeze()
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\freezer.py", line 570, in Freeze
    self.finder = self._GetModuleFinder()
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\freezer.py", line 318, in _GetModuleFinder
    argsSource.copyDependentFiles, compress = argsSource.compress)
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\finder.py", line 54, in __init__
    self._AddBaseModules()
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\finder.py", line 69, in _AddBaseModules
    self.IncludeModule("traceback")
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\finder.py", line 526, in IncludeModule
    namespace = namespace)
  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\cx_Freeze\finder.py", line 274, in _ImportModule
    raise ImportError("No module named %r" % name)
ImportError: No module named 'traceback'

D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\cx_Freeze>

7.改为:

#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Name:        【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件
# Purpose:      https://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;
from cx_Freeze import setup, 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 = "..\BlogsToWordpress";
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.py", base=base)])

效果是:问题依旧。

8.去查了下,果然还真有traceback模块:

traceback — Print or retrieve a stack traceback

但是是内置的标准模块,所以无法额外安装。

但是结果此处却找不到,说明本身此处,就没有正确识别python啊。。

9.手动再导入一下试试:

#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Name:        【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件
# Purpose:      https://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;
from cx_Freeze import setup, 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)])

结果是,问题依旧。

10.参考:

https://bitbucket.org/anthony_tuininga/cx_freeze/src/8913025af703/samples/simple/setup.py?at=default

中的简单例子,去删掉复杂的配置,变成:

#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Name:        【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件
# Purpose:      https://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;
from cx_Freeze import setup, 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")])

结果是,竟然就可以正常运行了:

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 file build\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
m time
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>

次奥!!!

 

【总结】

当使用cx_Freeze去打包exe出错

ImportError: No module named ‘traceback’

时,使用最简单的:

#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# Name:        【记录】用cx_Freeze把Python代码打包成单个独立的exe可执行文件
# Purpose:      https://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;
from cx_Freeze import setup, 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")])

然后执行:

setup.py bdist_msi

就正常了。。。

 

错误的根本原因,暂时未搞懂。

转载请注明:在路上 » 【已解决】Python中通过cx_Freeze去打包exe出错:ImportError: No module named ‘traceback’

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
88 queries in 0.182 seconds, using 22.24MB memory