简体   繁体   English

--noconsole 不适用于 Pyinstaller

[英]--noconsole not working with Pyinstaller

When I run my program using python myprogram.py , it runs as intended and no command prompt pops up.当我使用python myprogram.py运行我的程序python myprogram.py ,它按预期运行并且没有弹出命令提示符。 When I create an executable using pyinstaller myprogram.py -F --noconsole , a blank command prompt pops up.当我使用pyinstaller myprogram.py -F --noconsole创建可执行文件时,会弹出一个空白的命令提示符。 The title of this command prompt is the location of the wkhtmltopdf.exe program used within myprogram.py.这个命令提示符的标题是在 myprogram.py 中使用的 wkhtmltopdf.exe 程序的位置。 I don't think the issue is with wkhtmltopdf though since the command prompt doesn't show up when I run python myprogram.py .我不认为问题出在 wkhtmltopdf 上,因为当我运行python myprogram.py时没有显示命令提示符。 I think it's something with pyinstaller, but I thought using the --noconsole option would prevent this.我认为这是 pyinstaller 的问题,但我认为使用 --noconsole 选项可以防止这种情况。 I've also tried --windowed.我也试过 --windowed。

When you run PyInstaller on your project, does a .SPEC file also appear?当您在项目上运行 PyInstaller 时,是否还会出现 .SPEC 文件?

If so, edit the .SPEC file's exe field like so:如果是这样,请像这样编辑 .SPEC 文件的 exe 字段:

exe = EXE(
      ...,
      console=False,
      ...
      )

Then run PyInstaller on the .SPEC file.然后在 .SPEC 文件上运行 PyInstaller。

If a .SPEC file didn't appear before, try running PyInstaller on your project without any parameters (so just pyinstaller myProgram.py ).如果之前没有出现过 .SPEC 文件,请尝试在您的项目上运行 PyInstaller 而不带任何参数(因此只需pyinstaller myProgram.py )。 A .SPEC file should appear and you can edit it as above and then rerun PyInstaller.应该会出现一个 .SPEC 文件,你可以像上面一样编辑它,然后重新运行 PyInstaller。

Here is my suggestion on this: comment out all print statements.这是我对此的建议:注释掉所有打印语句。 Keep it simple, like so:保持简单,像这样:

pyinstaller --onefile  --noconsole <filename>.py

I was having lots of trouble getting the noconsole or windowed options to work on my Windows 10 machine.我在让noconsolewindowed选项在我的 Windows 10 机器上工作时遇到了很多麻烦。

I started with the .spec file generated by PyInstaller.我从.spec生成的.spec文件开始。
Somehow it had the line: [('v', None, 'OPTION')], in the EXE section.不知何故,它在EXE部分有一行: [('v', None, 'OPTION')],
When I commented that out, and added the nonconsole and windowed options, it worked!当我将其注释掉并添加非控制台和窗口选项时,它起作用了!
Here is the working section:下面是工作部分:

       a.scripts,
       # [('v', None, 'OPTION')],
       exclude_binaries=True,
       name='my program name',
       debug=False,
       bootloader_ignore_signals=False,
          strip=False,
          upx=False,
          console=False,
          windowed=True)

I can only guess that the offending line stopped PyInstaller from processing the rest of the EXE statement, and so it missed the options.我只能猜测有问题的行阻止了 PyInstaller 处理EXE语句的其余部分,因此它错过了选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM