0

我已经安装了 pyinstaller2.0**,并且在 Windows7-64 位操作系统上使用 Python 2.7.5 32 位。

我正在尝试创建一个没有控制台的应用程序。当我使用--noconsole并单击我生成的.exe它时,它不会打开。

如果我通过使用我的应用程序将控制台更改为 true--console运行得很好,但我有一个控制台。

我已经在这里和谷歌搜索了几个小时,并查看了其他教程,但我找不到这个问题的任何其他线程。

这就是我在批处理文件中用于编译我的 EXE 的内容

c:\python27_32\python.exe pyinstaller.py --onefile --noconsole c:\python27_32\tutorial5.py

这是我的警告文件;

W: no module named posix (conditional import by os)
W: no module named readline (delayed, conditional import by cmd)
W: no module named readline (delayed import by pdb)
W: no module named pwd (delayed, conditional import by posixpath)
W: no module named org (top-level import by pickle)
W: no module named posix (delayed, conditional import by __main__)
W: no module named posix (delayed, conditional import by iu)
W: no module named Crypt (delayed, conditional import by __main__)
W: no module named fcntl (conditional import by subprocess)
W: no module named AES (delayed, conditional import by __main__)
W: no module named org (top-level import by copy)
W: no module named _emx_link (conditional import by os)
W: no module named fcntl (top-level import by tempfile)
W: no module named AES (delayed, conditional import by archive)
W: __all__ is built strangely at line 0 - collections (c:\python27_32\lib\collections.pyc)
W: delayed  exec statement detected at line 0 - collections (c:\python27_32\lib\collections.pyc)
W: delayed conditional __import__ hack detected at line 0 - unittest.main (c:\python27_32\lib\unittest\main.pyc)
W: __all__ is built strangely at line 0 - dis (c:\python27_32\lib\dis.pyc)
W: delayed  __import__ hack detected at line 0 - encodings (c:\python27_32\lib\encodings\__init__.pyc)
W: delayed  __import__ hack detected at line 0 - optparse (c:\python27_32\lib\optparse.pyc)
W: delayed  __import__ hack detected at line 0 - ctypes (c:\python27_32\lib\ctypes\__init__.pyc)
W: delayed  __import__ hack detected at line 0 - ctypes (c:\python27_32\lib\ctypes\__init__.pyc)
W: delayed conditional __import__ hack detected at line 0 - unittest.loader (c:\python27_32\lib\unittest\loader.pyc)
W: delayed conditional __import__ hack detected at line 0 - unittest.loader (c:\python27_32\lib\unittest\loader.pyc)
W: delayed  __import__ hack detected at line 0 - unittest.loader (c:\python27_32\lib\unittest\loader.pyc)
W: delayed conditional __import__ hack detected at line 0 - doctest (c:\python27_32\lib\doctest.pyc)
W: delayed  exec statement detected at line 0 - doctest (c:\python27_32\lib\doctest.pyc)
W: delayed conditional __import__ hack detected at line 0 - doctest (c:\python27_32\lib\doctest.pyc)
W: delayed  exec statement detected at line 0 - pdb (c:\python27_32\lib\pdb.pyc)
W: delayed conditional eval hack detected at line 0 - pdb (c:\python27_32\lib\pdb.pyc)
W: delayed  eval hack detected at line 0 - pdb (c:\python27_32\lib\pdb.pyc)
W: delayed conditional eval hack detected at line 0 - pdb (c:\python27_32\lib\pdb.pyc)
W: delayed  eval hack detected at line 0 - pdb (c:\python27_32\lib\pdb.pyc)
W: __all__ is built strangely at line 0 - __future__ (c:\python27_32\lib\__future__.pyc)
W: __all__ is built strangely at line 0 - hashlib (c:\python27_32\lib\hashlib.pyc)
W: __all__ is built strangely at line 0 - tokenize (c:\python27_32\lib\tokenize.pyc)
W: __all__ is built strangely at line 0 - tokenize (c:\python27_32\lib\tokenize.pyc)
W: __all__ is built strangely at line 0 - wx (c:\python27_32\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.pyc)
W: __all__ is built strangely at line 0 - wx (c:\python27_32\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.pyc)
W: delayed  exec statement detected at line 0 - bdb (c:\python27_32\lib\bdb.pyc)
W: delayed  eval hack detected at line 0 - bdb (c:\python27_32\lib\bdb.pyc)
W: delayed  eval hack detected at line 0 - bdb (c:\python27_32\lib\bdb.pyc)
W: delayed  __import__ hack detected at line 0 - pickle (c:\python27_32\lib\pickle.pyc)
W: delayed  __import__ hack detected at line 0 - pickle (c:\python27_32\lib\pickle.pyc)
W: delayed conditional exec statement detected at line 0 - iu (C:\pyinstaller\PyInstaller\loader\iu.pyc)
W: delayed conditional exec statement detected at line 0 - iu (C:\pyinstaller\PyInstaller\loader\iu.pyc)
W: delayed  eval hack detected at line 0 - gettext (c:\python27_32\lib\gettext.pyc)
W: delayed conditional eval hack detected at line 0 - warnings (c:\python27_32\lib\warnings.pyc)
W: delayed conditional __import__ hack detected at line 0 - warnings (c:\python27_32\lib\warnings.pyc)

这是我的规范文件输出;

# -*- mode: python -*-
a = Analysis(['c:\\python27_32\\tutorial5.py'],
             pathex=['C:\\pyinstaller'],
             hiddenimports=[],
             hookspath=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name=os.path.join('dist', 'tutorial5.exe'),
          debug=False,
          strip=None,
          upx=True,
          console=True )
app = BUNDLE(exe,
             name=os.path.join('dist', 'tutorial5.exe.app'))

如果我有控制台,一切都很好,但如果我不想要控制台,什么都不会发生..

我有什么明显的遗漏吗?

我感谢您的帮助。

文斯特

4

1 回答 1

0

如果您从不打开任何 GUI 窗口或类似的东西,依靠控制台进行用户 I/O,并且还抑制控制台出现,程序将静默启动(即不打开任何窗口),这可能会出现它没有运行。

要检查这一点,您有几个选择。

  1. 制作一个只停留一段时间(sleep(30)或其他东西)的玩具应用程序。编译。跑。打开任务管理器并查找它。如果它在那里,我的假设是正确的。
  2. 制作一个玩具应用程序,在某个已知的地方(比如你的桌面)创建一个文件。编译。跑。如果出现文件,我的假设是正确的。
  3. 制作一个显示对话框的玩具应用程序。编译。跑。如果出现对话框,我的假设是正确的。

基本上,如果你不想打扰控制台,你需要

  1. 与用户交互的其他方式,通常是 GUI;或者
  2. 在无法查询或向用户显示结果的情况下程序如何运行的计划。

tl;博士

您不能只是摆脱控制台并期望程序不变地运行。它将运行,但无法请求输入或显示结果。没有什么魔法能让 GUI 出现在你面前。

于 2013-06-08T10:01:23.053 回答