首页 > 解决方案 > 使用 py2exe 编译时编译失败

问题描述

我使用此代码编译我的程序:

#Packages
from distutils.core import setup
import sys
import shutil
import os

sys.argv.append ("py2exe")#Auto call py2exe

if os.path.exists ("dist"):#Remove previous build
    shutil.rmtree ("dist")

setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
    windows = [{
        "script" : "main.py",
        "icon_resources" : [(0, "app.ico")]
    }],
    zipfile = None,
)

shutil.copy ("tool.exe", "dist/tool.exe")#Copy used tools

它工作了一段时间,但我在项目的其余部分工作时有一段时间没有使用它,但是当我尝试编译它时显示此错误:

C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\distutils\dist.py:274: UserWarning: Unknown distribution option: 'windows'
  warnings.warn(msg)
C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\distutils\dist.py:274: UserWarning: Unknown distribution option: 'zipfile'
  warnings.warn(msg)
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: invalid command 'py2exe'

我已经更新并重新安装了 python,以及 pip 和程序使用的所有库,但错误仍然存​​在。

标签: python-3.xpy2exe

解决方案


推荐阅读