当我运行一个非常简单的py2exe测试时,它会给我错误

时间:2012-06-07 18:34:56

标签: python exe py2exe

我写了一个名为test.py的非常简单的程序,如下所示:

print 'hello world'

然后我写了一个名为setup.py的安装程序,如下所示:

from distutils.core import setup
import py2exe

setup(console=['test.py'])

它们都在同一个文件夹中,因此它应该可以工作。当我运行setup.py时,它给出了如下所示的错误消息:

C:\Python26\lib\sets.py:85: DeprecationWarning: functions overriding warnings.showwarning() must support the 'line' argument
  stacklevel=2)
Traceback (most recent call last):
  File "C:\Users\python2.6\Desktop\program\pygametests\setup.py", line 5, in <module>
    setup(console=['test.py'])
  File "C:\Python26\lib\distutils\core.py", line 140, in setup
    raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
SystemExit: 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: no commands supplied

我正在运行Windows Vista。

1 个答案:

答案 0 :(得分:3)

您应该转到您拥有文件的文件夹并运行:

C:\Python27\mydir> python setup.py py2exe

或直接

C:\Python27\mydir> setup.py py2exe

回溯告诉你你没有在命令行中为setup.py发送任何命令(在我的例子中为'py2exe')

您可以通过以下方式查看可用命令:

C:\Python27\mydir>setup.py --help-commands
Standard commands:
  build            build everything needed to install
  build_py         "build" pure Python modules (copy to build directory)
  build_ext        build C/C++ extensions (compile/link to build directory)
  build_clib       build C/C++ libraries used by Python extensions
  build_scripts    "build" scripts (copy and fixup #! line)
  clean            clean up temporary files from 'build' command
  install          install everything from build directory
  install_lib      install all Python modules (extensions and pure Python)
  install_headers  install C/C++ header files
  install_scripts  install scripts (Python or otherwise)
  install_data     install data files
  sdist            create a source distribution (tarball, zip file, etc.)
  register         register the distribution with the Python package index
  bdist            create a built (binary) distribution
  bdist_dumb       create a "dumb" built distribution
  bdist_rpm        create an RPM distribution
  bdist_wininst    create an executable installer for MS Windows
  upload           upload binary package to PyPI
  check            perform some checks on the package
  py2exe

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


C:\Python27\mydir>