【发布时间】:2014-09-08 01:34:58
【问题描述】:
当我的 python 脚本运行时,如何从桌面上删除这个黑色的命令提示符屏幕?
我使用 python 2 exe 将 service.py 脚本变成了 exe。一切正常,但是当 .exe 运行时,我有一个固定的命令提示符,我不想显示。
service.py:
#!/usr/bin/env python
import os
import ctypes
from subprocess import Popen, PIPE
def Mbox(title, text, style):
ctypes.windll.user32.MessageBoxA(0, text, title, style)
python_check = os.path.exists("C:/Python27/python.exe")
g_check = os.path.exists("C:/dev_appserver.py")
if python_check & g_check:
p0 = Popen(['C:/Python27/python.exe', 'C:/dev_appserver.py', '--host', '0.0.0.0', '--port', '8080', 'C:/application'], stdout=PIPE, stdin=PIPE, stderr=PIPE, shell=True)
out, err = p0.communicate("n\n")
else:
Mbox('Notice', 'Launching service failed please make sure C:\Python27\python.exe and C:/dev_appserver.py', 0)
setup.py:
from distutils.core import setup
import py2exe
setup(console=['service.py'])
【问题讨论】:
-
我同意@Trimax 的回答,但我想推荐 pyinstaller,因为它更简单且支持更多。对于一个简单的文件,没有控制台.... pyinstaller service.py --noconsole --onefile
-
@dev247 pyinstaller 支持 Python 3.3+ 吗?
-
@Trimax No PyInstaller 和 py2exe 都只支持 Python 2.7。看到这个StackOverflow 条目,基本上你必须使用cx_freeze。
-
另外你可以看到support listings here
-
但是,我现在使用 py2exe 0.9.2 和 Python 3.4 并且工作正常。在 pypi 中:pypi.python.org/pypi/py2exe/0.9.2.0
标签: python windows command-prompt py2exe