I have a weird issue on a friends machine where when they run my script, it only flashes the command window when it hits a line that does something with os.system. It seems to not show the command window at all otherwise. Not showing is fine, but my script does a large process and it causes the window to flash a lot.
Normally on my machine, when I open the script (that launches a gui with tkinter) the command window will open as well in the back. This is what I am trying to get my friends to do, but I do not know what would cause the command window to not show. Is there a setting within python somewhere that doesn't show the command window (unless of course it needs to run a process in it)?
Edit: Ok I did a really lame hack to fix this. Apparently all he .py files got associated with pythonw. I was unable to get this association changed (even going through the command prompt ASSOC) So I just did a silly renamed of the pythonw to old_pythonw, and renamed the python.exe to pythonw.exe. Yes, really silly but no time to argue with windows about file associations.
Related
Hello so I'm kind of new with programming and I buildt a program with python and kivy. The issue is that I am using auto-py-to-exe to convert the py files to exe but when I do it, it doesn't work well. The primary issue is that a windows command prompt opens when I run the app and if I close it, the app closes too. The other problem is that I can't share the file to someone else so that they can run it in another computer, and what happens is that the same command prompt kind of appears but then closes and the app doesn't open at all. I would appreciate it if someone could help me to understand how I can debug it as I don't even understand the problem in the first place.
I have been looking online for other people with the same issues but I haven't find any answer that applied to my case.
Try to choose Window Based(hide the console) and it wil works
If you choose “Console Based,” the console will open after running the executable file, which is recommended if your script generates console-based outputs. However, if you don’t want to show the console outputs when running the executable file, choose “Window Based”
Just when I thought I am 100% done with my app, turns out I was wrong. The app uses APScheduler to run several events at the same time and until now had been tested only in development mode, by bundling it in a single .exe file using Pyinstaller with the console visible for debugging purposes.
Very pleased I can finally remove the console window to distribute it to others, I was surprised to see that removing the console appears to mess up how APScheduler works. The times the tasks should be performed are wrong. Instead of the next time a task should run, it sets the current time, and no scheduled events are being executed. I have tried dragging it into the cmd to see if it shows any errors there, but it just stays blank. Everything else seems to be working fine, the GUI, the system tray code, the SQL tables, etc..
Briefly, the code I use is:
pyinstaller --add-data images.png;. --onefile --icon=trayicon.ico -w script.py
I also tried --windowed command. Funnily enough, --noconsole shows as an unrecognised argument.
I tried making it into a .pyw file but the same problem is observed.
Can anyone perhaps explain:
What actually happens on a deeper level when one removes the console/window from the executable? This might set me on the right path to figuring out the mess up with APScheduler.
Is there a way to just hide the console/window in the background, instead of removing it entirely?
PS: I am using Windows 10, Anaconda 3, Python 3.7.6, Spyder IDE
SOLUTION:
Still not sure why (the lack of) console messes up the programme, but if anyone encounters similar problem in the future, I fixed it by creating the .exe with a window, and HIDING the console window using the following command at the very start of my code:
import win32gui
win32gui.ShowWindow(win32gui.GetForegroundWindow(), win32con.SW_HIDE)
I have written a simple software for creating passwords. But when converted to exe and run file, the terminal screen closes after about 1 second.I have also installed all the modules. The software is available at the link below.Please help me.
https://gofile.io/d/0G6N1o
The reason it is closing is because your application completed. You either need to have a dialog box which allows the user to click close, or at a minimum a sleep before you call exit(). This is the same for a .bat script in which the behavior you describe is a terminal window flickering for a second and going away.
I've written a little GUI with tkinter for my own purposes on my Mac. I've written a two-line bash script to run it, and I can launch it from my desktop by double-clicking an icon. This is fine, but it pops up a terminal window, which I find annoying.
I would like to have it run as an app, without opening a terminal window. I followed the instructions in ccpizza's answer to create an app with Automator. I chose /usr/bin/python as the shell, and pasted in my python code. When I click on the desktop icon, I get an error box that says,
The action “Run Shell Script" encountered an error.
The console log has the error,
LaunchServices: Could not store lsd-identifiers file at /private/var/db/lsd/com.apple.lsdschemes.plist
I saw that /private/var/db/lsd is owned by root and I am the owner of the app. I tried
sudo chown root <appname>
and it doesn't give an error, but I am still shown as the owner of the app.
I've also tried choosing usr/local/bin/bash as the shell script, pasting in my bash script. When I run click the icon, I don't even get an error box, but the same error shows up in the console log.
Is there an easy fix for this? I'm just interested in getting this method to work. I'd rather not do anything more elaborate, like installing py2app or platypus.
I ended up getting platypus. It was trivial to do what I wanted. Just pick "None" for the interface.
If you just want to write a python script and run as a app, you can try pyinstaller.
I have no idea if this problem has the solution I want but here goes.
I'm making a PyQt4 program that apparently needs the console window to run properly. However, whenever I activate another window, sending the program I'm working on to the back, the only way I can get back to it is by closing all the windows in front of said window. I can't just click on the taskbar because the only thing that comes back is the console window.
I'm curious. Is there a way to have the GUI window activate along with, or independent of, the console window without having to go through the annoying process of closing (minimizing) potentially all the rest of your windows?
Edit: I just realized my question is pretty vague. Let me elaborate.
I'm compiling said program using pyinstaller.
The reason it needs the console window to work properly (I have tried using the .pyw file as well, to no avail) is because there's another program that's the core of this one that prints out to it in a way I can only describe as violently.
Apparently it won't be happy unless it has the console to record it's outbursts.
That being said, I need the console window. However, as I mentioned before, that is the only thing that comes up when the pyinstaller icon is clicked.
There is a gui attached to the console, but there's no way to get it back even after the user would minimize it because the pyinstaller icon insists it doesn't exist.
Maybe it has something to do with how I defined the window while programming it, but I don't see why that would be the case. Is there something in particular pyinstaller doesn't like that would make it act like this?
How are you launching the PyQt application?
If you're launching it with the python executable, it will create a console.
python my_application.py
Instead, launch it with the GUI version of python -- pythonw:
pythonw my_application.py
If the python path isn't in the system path, you may need to specify the whole path to the executable:
C:\python27\pythonw.exe C:\path\to\my_application.py