2016-12-07 104 views
0

我正在嘗試使用py2exe來執行腳本。AttributeError:'NoneType'對象沒有屬性'split'?

這裏是我的setup.py代碼:

import cx_Freeze 

executables = [cx_Freeze.Executable("Email.py")] 

cx_Freeze.setup(
    name="Email", 
    options={"build_exe": {"packages":["pygame"], 
          "include_files":["aura.png"]}}, 
    executables = executables 

    ) 

我跑這從我的cmd,然後在這裏是執行:

G:\Grade 12 Project>python setup.py build running build running build_exe creating directory build\exe.win32-2.7 copying C:\Python27\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.win32-2.7\Email.exe copying C:\WINDOWS\SYSTEM32\python27.dll 
-> build\exe.win32-2.7\python27.dll Traceback (most recent call last): File "setup.py", line 9, in <module> 
    executables = executables File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 349, in setup 
    distutils.core.setup(**attrs) File "C:\Python27\lib\distutils\core.py", line 151, in setup 
    dist.run_commands() File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands 
    self.run_command(cmd) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command 
    cmd_obj.run() File "C:\Python27\lib\distutils\command\build.py", line 127, in run 
    self.run_command(cmd_name) File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command 
    self.distribution.run_command(command) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command 
    cmd_obj.run() File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 219, in run 
    freezer.Freeze() File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 623, in Freeze 
    self._FreezeExecutable(executable) File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 225, in 
_FreezeExecutable 
    self._AddVersionResource(exe) File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 165, in 
_AddVersionResource 
    trademarks = exe.trademarks) File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 759, in 
__init__ 
    parts = version.split(".") AttributeError: 'NoneType' object has no attribute 'split' 

而且在我的build文件夾,當我運行Email.exe,我得到這個錯誤:

ImportError: No module named __startup__ 
+1

我想你也必須提供版本號。它試圖分割「x.x.x」類型的字符串,但由於您沒有提供它,所以會引發錯誤。 – MYGz

+0

@amin,這是一個微不足道的編輯。 –

+0

@MohammadYusufGhazi,版本號? –

回答

1

As @Mohammad Yusuf Ghazi說,你需要通過一個version='x.y.z'參數到建立呼叫,e.g:

cx_Freeze.setup(
    name="Email", 
    options={ 
     "build_exe": {"packages":["pygame"], 
     "include_files":["aura.png"]}}, 
    executables = executables, 
    version='1.0.0' 
) 

這不是有效的調用setup沒有版本號。

你試圖從命令行或從GUI運行此?如果來自GUI,您可能需要根據the docs調用Executable("Email.py", base="Win32GUI")以使其工作,以便可能是是問題。但它有助於看到完整的追溯。