windowed exe using pyinstaller with -w option not work - python

This is my first post, thanks for viewing in advance.
I wanted to convert test.py to test.exe using pyinstaller. Everything worked fine until I tried to use -w option to get rid of the console window. It says-
'Failed to execute script test'
Below is the code -
from selenium import webdriver
browser = webdriver.Firefox()
I guess when using '-w' option for script with external applications like browser it will pop up with this error?
Thanks guys

your script is fine, it's the way you are using pyinstaller. to get rid of the console window you need pyinstaller added to your system path and then type this in a regular command prompt:
pyinstaller script.py --windowed

Related

How to hide cmd console when excute .exe program compiling by Nuitka?

I used this (python -m nuitka --follow-imports program.py) command to compile my script using Nuitka . It made an .exe file which worked quite well for me other than --onefile commands , as they were showing me import error. But here the problem is , a cmd console opens up of my .exe file after is start it, then my tkinter gui console shows up. I tried to use .pyw file to compile my script, but it didn't help me. I need help to shutdown or hide that cmd console window which pops up for my .exe file.

Python app not working after using pyinstaller but doesn't give any errors

So I made an app using python and kvlang, and I was trying to get all the files into a one standalone "exe" file. I needed to include the ".kv" file and my main script. I was using pyinstaller and wrote this command:
pyinstaller --onefile -w --icon=download.ico --add-data filefinder.kv;. filefinder.py
And it all went well - no errors or anything but when I launch the app I just get a quick flash of a white window and then it closes. I have determined that the error must be because of some issue with the ".kv" file but I am not able to fix it cause there's no errors, Nothing! I checked and the app works with the "onedir" option but I need to make it smaller in size. I also tried the "auto-py-to-exe" but it gives the same result. I am happy to provide any more info should you need it to help me resolve this issue. Cheers!
Additional info:
System: Windows 10 pro
Python: 3.9.1
kivy: 2.0.0
Pyinstaller: 4.2
Not sure why it doesn't work, but run the exe in command prompt and then when it fails the error message will not disappear.
Add lots of logs to your application, these can be print statements, as those will always end up on stdout.
i.e. on the first entrypoint, print("Running main")
When you call your first function:
print('calling function_name()')
Once that has finished
print('function_name() complete')
And so on and so forth until you find where exactly the program stops functioning.
Start -> cmd -> navigate to your file using cd -> type in the name of the exe to run it.

Pyinstaller opens command prompt

I'm still a beginner with coding so maybe this question will be trivial for some of you. My apologies in advance.
For a project, i made a webcrawler using python and selenium, with an user interface made with Tkinter. I use a chromedriver to open chrome for the webcrawling part.
I converted my Tkinter file with pyinstaller into an executable file. When doing so, i typed the following flags: --onefile -w
I was told that the latter one prevents opening a command prompt when running the file, however, when i run the executable, my pc opens the command prompt for the chromedriver. How can i fix this?
-w will prevent the creation of a console for the main exe, not for the execution of the chromedriver.
You should have a look at ChromeDriver console application hide thread for removing the console created by chromedriver

Getting rid of chromedirver console window with pyinstaller

I'm using chromedriver in headless mode. I compile the script using pyinstaller as one exe file. Everything works fine, except that I get the following console window whenever I open a chrome page:
I've tried the options --windowed alone, --noconsole alone, --windowed and --noconsole together but I still get this window.
How can I get rid of it?
I was able to find the following answer and it's working perfectly for me:
To avoid getting console windows for chromedriver, open the file
Python\Lib\site-packages\selenium\webdriver\common\service.py
and change
self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file, stdin=PIPE)
To:
self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE ,stderr=PIPE, shell=False, creationflags=0x08000000)
I had a similar issue, I'd like to share how I fixed it. First I'll describe the context:
-- My script worked well, it opened chrome windows normally (not headless).
-- I used pyinstaller (with the onefile and noconsole commands).
-- The EXE worked but every time it opened a chrome window, it opened a console window as well, I don't remember what the window said, but it wasn't an error.
-- I tried the solution that Ahmed post, and it worked that day.
-- Next day I tried the EXE in various computers, and the problem came back.
-- I posponed that problem since it wasn't a fatal error and there were more important issues to resolve in my app. So while I was trying to fix another issue, I found this answer: https://stackoverflow.com/a/56839122/13988982.
-- Basically it said that changing the order of the commands that you use when you run pyinstaller, actually affects how the EXE file is packaged. (I'm not sure why).
-- I ran: pyinstaller --add-binary "chromedriver.exe;." --noconsole --onefile myApp.py
And that finally made the console window not to show anymore.
Hope this is useful for anyone.

Making a PyInstaller exe do both command-line and windowed

I am writing a Python program that can be used both on the command-line, and as an interactive window. (Is that a bad idea?) If command-line arguments are supplied, it executes a task, then prints "success" or "failure". Otherwise, it launches an interactive window.
PyInstaller doesn't seem to be built to support this. I have two non-optimal options:
Use --console mode: The command-line works great, but if I double-click the exe to show the interactive window, it also shows a console window that I don't want
Use --noconsole mode: There's no console popup, but no output shows when using the command-line.
It seems I either need a way to not pop-up the console in --console mode, or to show print output in --noconsole mode. If neither of those options work, I may need to make a separate command-line version of the program.
Any advice?
This is not a perfect solution, but this workaround did the job for me:
Build gui app in --noconsole --one file mode like this:
pyinstaller --noconsole --onefile hello.py
When you double click on the app from windows it will launch normally (without the console).
Now to see the output, navigate to the executable from the command line and type:
hello.exe | more
The "| more" should send the print statements to the console.
This is a problem with Windows (not PyInstaller), which requires the subsystem to be specified as either CONSOLE or WINDOWS at compilation-time.
https://github.com/pyinstaller/pyinstaller/issues/6244#issuecomment-927131015
The recommended solution is to split your app (eg hello) into two distinct versions:
hellow.exe for the GUI version (windowed) and
hello.exe for the CLI version (console)
In theory, you could also add a wrapper .exe that switches between the two actual binaries above, depending on how it's called..

Categories

Resources