简体   繁体   中英

--noconsole not working with Pyinstaller

When I run my program using python myprogram.py , it runs as intended and no command prompt pops up. When I create an executable using pyinstaller myprogram.py -F --noconsole , a blank command prompt pops up. The title of this command prompt is the location of the wkhtmltopdf.exe program used within myprogram.py. I don't think the issue is with wkhtmltopdf though since the command prompt doesn't show up when I run python myprogram.py . I think it's something with pyinstaller, but I thought using the --noconsole option would prevent this. I've also tried --windowed.

When you run PyInstaller on your project, does a .SPEC file also appear?

If so, edit the .SPEC file's exe field like so:

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

Then run PyInstaller on the .SPEC file.

If a .SPEC file didn't appear before, try running PyInstaller on your project without any parameters (so just pyinstaller myProgram.py ). A .SPEC file should appear and you can edit it as above and then rerun 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.

I started with the .spec file generated by PyInstaller.
Somehow it had the line: [('v', None, 'OPTION')], in the EXE section.
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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