2014-02-22 101 views
1

我試圖在32位Ubuntu上使用cx_freeze創建我的第一個.exe文件,但遇到了無法解釋的TypeError。我希望我在我的設置文件中做了一些錯誤的事情,但還沒有找到它可能是什麼。下面是安裝腳本:使用cxfreeze時出現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文件。

回答

0

我不是cx_freeze專家,但您的可執行文件定義看起來不正確。 packages參數應該包含(即包含__init__.py和零個或多個其他Python文件的文件夾)列表,而不是Python 模塊(個人.py文件)。

有關模塊和包之間的區別的詳細信息,請參閱http://docs.python.org/2/tutorial/modules.html

+0

事實上,'packages'可以採取模塊以及 - 命名有點令人迷惑 - 但*不應*有'.py'延期。 –

相關問題