4

我写了一个非常简单的名为 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。

4

1 回答 1

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>
于 2012-06-07T18:38:52.770 回答