在Python 3.3中将.py文件编译为.exe

时间:2015-03-02 16:34:54

标签: python python-3.x py2exe

我无法让py2exe正常工作。

我希望将此test.py转换为test.exe:

test.py代码:

print("Hello World!")

修改

显然我使用了python 2.x方法。当我改为使用3.3命令时:

 py -3.3 -m py2exe.build_exe test.py

我收到了新错误:

 D:\program\python\lib\distutils\dist.py:257: UserWarning: Unknown     distribution o
 ption: 'console'
 warnings.warn(msg)
 invalid command name 'test.py'

感觉好像我只是经常撞到墙上。对此新错误的任何见解?

帖子的旧部分:

我使用以下代码创建了一个setup.py:

from distutils.core import setup
import py2exe

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

我用pip安装了py2exe(ver 0.9.2.2)。当我移动到包含setup.py和test.py的文件夹并运行命令:

python setup.py py2exe

我遇到了错误:

 D:\program\python\lib\distutils\dist.py:257: UserWarning: Unknown distribution o
 ption: 'console'
   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'

1 个答案:

答案 0 :(得分:0)

python文档不鼓励使用distutils模块。而是使用setuptools如下

from setuptools import setup
import py2exe

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

在python 3下,您无法使用py2exe查看FAQ了解详情。

相关问题