【问题标题】:pyinstaller2.0 --noconsole won't run my exe when I click on itpyinstaller2.0 --noconsole 当我点击它时不会运行我的 exe
【发布时间】:2013-06-08 09:46:28
【问题描述】:

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

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

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

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

这是我的批处理文件中用于编译我的 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'))

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

我有什么明显的遗漏吗?

感谢您的帮助。

温斯特

【问题讨论】:

    标签: python pyinstaller


    【解决方案1】:

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

    要检查这一点,您有多种选择。

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

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

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

    tl;博士

    您不能只是摆脱控制台并期望程序不变地运行。它将运行,但无法请求输入或显示结果。没有任何魔法可以为您显示 GUI。

    【讨论】:

    • 我使用我编写的另一个应用程序进行了尝试,它按预期工作。 --noconsole 符合我的预期。现在要弄清楚为什么我需要它的应用程序不起作用?我正在使用 wxWidgets 和 wxpython .. 库在我的路径中,所以我不认为这会导致这种情况......由于链接断开,我本来预计会出现编译错误。
    • @Vinster411 那个不同的应用程序是什么?我需要更多信息。
    • 我很早就在 GUI 应用程序之间测试了我将要使用什么来构建我的 GUI/应用程序。我浏览了一个教程,我在网上找到了创建一个带有文件菜单和关闭按钮的基本 Windows 窗体......非常小而简单,它是并排的......一个应用程序使用 Tkinter 工具,另一个使用 wxWidgets。我发现使用 wxWidgets 比使用 Tkinter 更容易,所以我现在在 wxwidgets 中做了几个星期的工作。我现在不在我的 Work 笔记本电脑上。我的应用程序有 5 个版本/迭代作为里程碑保存。我会看看我是否可以使用 --noconsole 构建和运行它们中的任何一个......
    • (对不起,多个链接帖子,我的空间用完了)我找到了我使用的教程:link 然后我建立了我的 wxwidgets,但添加了许多导入,其中任何一个都可以导致问题...
    • @Vinster411 好吧...当您检查这些内容时,请查看 GUI 窗口是否同时出现在控制台和非控制台模式下。如果是这样,那就有问题了。
    猜你喜欢
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多