【问题标题】:AttributeError: 'NoneType' object has no attribute 'split'?AttributeError:“NoneType”对象没有“拆分”属性?
【发布时间】:2016-12-07 08:08:29
【问题描述】:

我正在尝试使用py2exe 使脚本可执行。

这是我的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'

同样在我的构建文件夹中,当我运行Email.exe 时,我得到了这个错误:

ImportError: No module named __startup__

【问题讨论】:

  • 我认为您还必须提供版本号。它正在尝试拆分“x.x.x”类型的字符串,但由于您没有提供它,它会抛出错误。
  • @amin ,这是一个微不足道的编辑。
  • @MohammadYusufGhazi ,版本号?
  • 设置函数内部。检查这个:cx-freeze.readthedocs.io/en/latest/distutils.html
  • @MohammadYusufGhazi,我很抱歉。我无法理解你。

标签: python python-2.7 cx-freeze attributeerror


【解决方案1】:

正如@Mohammad Yusuf Ghazi 所说,您需要将version='x.y.z' 参数传递到设置调用中,例如:

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") 才能使其工作,因此 可能 是问题所在。但这将有助于查看完整的回溯。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-01
    • 2021-12-26
    • 2019-07-23
    • 2018-05-13
    • 2020-09-07
    • 2017-05-03
    • 2023-03-16
    • 2018-07-14
    相关资源
    最近更新 更多