使用cx_freeze时的TypeError

时间:2014-02-22 17:21:40

标签: python python-3.x cx-freeze

我试图在32位Ubuntu上使用cx_freeze创建我的第一个.exe文件,但遇到了一个无法解释的TypeError。我希望我在我的安装文件中做错了什么,但还没有找到它可能是什么。这是设置脚本:

import sys
from cx_Freeze import setup, Executable


exe = Executable(
    script = 'cornell7.py',
    targetName = 'cornell7.exe',
    packages = ['header2.py'],
    targetDir = 'executable_dir',
    includes = [    'urllib.request', 'socket', 'sys', 'string', 'threading', 'time','datetime'],
    copyDependentFiles = True
    )
setup(    name = 'cornell7.exe',
          executables = [exe]
     )

(header2.py是我自己写的一个包含几个有用功能的模块)

以下是我在终端中运行的命令:

 python setup.py build

当我输入该命令时,收到以下错误消息:

running build
running build_exe
Traceback (most recent call last):
   File "setup.py", line 14, in <module>
      executables = [exe]
   File "/usr/lib/pymodules/python2.7/cx_Freeze/dist.py", line 278, in setup
     distutils.core.setup(**attrs)
   File "/usr/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
     cmd_obj.run()
   File "/usr/lib/python2.7/distutils/command/build.py", line 128, in run
     self.run_command(cmd_name)
   File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
     self.distribution.run_command(command)
   File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
     cmd_obj.run()
   File "/usr/lib/pymodules/python2.7/cx_Freeze/dist.py", line 165, in run
     freezer.Freeze()
    File "/usr/lib/pymodules/python2.7/cx_Freeze/freezer.py", line 405, in Freeze
     self._FreezeExecutable(executable)
   File "/usr/lib/pymodules/python2.7/cx_Freeze/freezer.py", line 149, in _FreezeExecutable
    scriptModule = finder.IncludeFile(exe.script, exe.moduleName)
  File "/usr/lib/pymodules/python2.7/cx_Freeze/finder.py", line 391, in IncludeFile
    deferredImports)
  File "/usr/lib/pymodules/python2.7/cx_Freeze/finder.py", line 286, in _LoadModule
     self._ScanCode(module.code, module, deferredImports)
   File "/usr/lib/pymodules/python2.7/cx_Freeze/finder.py", line 353, in _ScanCode
     module, relativeImportIndex)
   File "/usr/lib/pymodules/python2.7/cx_Freeze/finder.py", line 176, in _ImportModule
     deferredImports)
  File "/usr/lib/pymodules/python2.7/cx_Freeze/finder.py", line 246, in _InternalImportModule
     parentModule)
   File "/usr/lib/pymodules/python2.7/cx_Freeze/finder.py", line 286, in _LoadModule
     self._ScanCode(module.code, module, deferredImports)
   File "/usr/lib/pymodules/python2.7/cx_Freeze/finder.py", line 353, in _ScanCode
     module, relativeImportIndex)
   File "/usr/lib/pymodules/python2.7/cx_Freeze/finder.py", line 176, in _ImportModule
     deferredImports)
   File "/usr/lib/pymodules/python2.7/cx_Freeze/finder.py", line 241, in _InternalImportModule
     fp, path, info = self._FindModule(searchName, path)
   File "/usr/lib/pymodules/python2.7/cx_Freeze/finder.py", line 84, in _FindModule
     for location in path:
 TypeError: 'NoneType' object is not iterable

据我所知,我已忠实地遵守cx_freeze文档。

1 个答案:

答案 0 :(得分:0)

我不是cx_freeze专家,但您的可执行文件定义看起来不对。 packages参数应该包含的列表(即包含__init__.py和零个或多个其他Python文件的文件夹),而不是Python modules < / em>(个人.py个文件)。

有关模块和软件包之间差异的更多信息,请参阅http://docs.python.org/2/tutorial/modules.html