I have an application I run using pythonw.exe. I just click on my .pyw file and it runs. It's using Qt and I have set up an icon that both shows in the window and in the taskbar.
However when I try to pin it, it pins the python IDLE incorrectly instead of the application itself. It makes some sense since it is a python file run from pythonw.exe. Example below:
So how do I proceed to run the application the right way so I can pin it to the taskbar?
As eryksun said you need a shortcut with pythonw.exe "Path to pyw file" in target.
Related
I have built a small desktop application which edits data(.ags format) and then saves to selected folder. Before i had an issue that, i could run it as python file, but it would crash when I make it .exe. I figured out the problem. The reason was that, particular line of code tries to prints to terminal, but .exe did not have it. I deleted sg.output() line from code, then used pyinstaller to make it .exe. Earlier i was using psgcompiler.
Now it works fine. However, when i open software the terminal opens as well (attached photo). Is there any chance to hide it, or add it to software itself? I tried multiline.
I have tried to add, but it did not work.
[sg.Multiline(size=(55, 5), reroute_stdout=True)],
Thanks
By default pyinstaller compiles executables in console mode... which means that unless you tell it otherwise when the application is run outside of the command line, e.g. by double clicking the .exe a console window will always appear.
To avoid this simply use the windowed mode of pyinstaller with the -w flag when compiling.
pyinstaller -w myapp.py
When I run the .exe from my project folder from terminal with dist\app\app.exe it runs fine, I can see my output in terminal etc.
However, with double-clicking the .exe I just get a flashing terminal window.
Does anyone have an idea or a clue?
By inspiration of the following post: PyInstaller .exe file does nothing I tried using --noupx in my installer command, and this lets me app run by double-clicking while having a terminal window on the background (which I am fine with for now).
When double-clicking you are going to run your application and it will close immediately after completion. The only exception is if the application is going to ask for input. This means that your application most likely runs fine.
It is also possible that you opened cmd-line as Administrator and thanks the application runs fine but when you double-click it is not being executed because it lacks access. It is not possible to tell without a closer investigation though.
I would like to have an executable (Windows, MacOS, Linux) of my program that will have its own terminal window where users will be able to type in. I don't want to have the user install modules or anything except this executable. You could say that the UI of my program would be a terminal window. Is it possible and with what?
I basically want the GUI of my app to be a terminal window.
To create a command-line interface for your program you'll likely want to use something like argparse, which is in the standard Python library. There are many other feature-rich command-line interface modules (e.g., click) you could try to use instead. You can design command-line interactions for your users including input and output, menus, etc.
Once you've built your application, a good choice to make it portable is the PyInstaller module. If you set the --onefile option when invoking it, it will generate a single .exe file which can be easily shared with users. If you also set the --console option when invoking PyInstaller, then your Python .exe application will interface with stdin/stdout. On Windows, this would be a cmd window.
If a user invokes your .exe via the GUI (e.g., a double-click on its icon), a Windows CMD window will be opened. If you want that window to stay open, however, you will need to create your application with some kind of "infinite"/"captive" design that never finishes executing until the user explicitly quits.
If the user instead runs the .exe from a Windows CMD terminal that is already open, then that window will always stay open.
I suspect you're looking for curses, or UniCurses if you're stuck with Microsoft Windows.
Many terminal emulators will allow you to start them up with a command line option that specifies a command to run in that emulator instead of your default shell.
I have created a script in python and saved it as .pyw file so that I don't need console to execute the script. I am wondering how to stop the execution once it is running. What I am doing right now is opening the IDLE and closing it and it seems to work. I am sure there is a better way of doing this. Can somebody advise me about this?
As it says in the docs
The Python installer automatically associates .py files with python.exe so that a double-click on a Python file will run it as a script. The extension can also be .pyw, in that case, the console window that normally appears is suppressed.
The .pyw extension is really meant to be used by Python GUIs. Since they create their own windows, the console window isn't required. If a .pyw script doesn't create any GUI windows, killing the python process is the only way to stop execution.
If you don't want to use the console to run your script (using the .py extension), just double-click on it.
I'm trying to hide the Terminal when I launch a GUI Tkinter based app, but when I double click the app.py file on OSX, the Terminal window appears. I've tried changing the extension to .pyw and tried launching it with /usr/bin/pythonw, but no matter what, the Terminal window still appears.
I've even tried adding the try/except below, but when I run it I get the error: 'invalid command name "console"' in the Terminal window that appears.
from Tkinter import *
class MainWindow(Tk):
def __init__(self):
Tk.__init__(self)
try:
self.tk.call('console', 'hide')
except TclError, err:
print err
win = MainWindow()
win.mainloop()
I haven't been able to find any way to hide the Terminal window from appearing. Anybody got any ideas?
By double-clicking a .py file on OS X, you are likely launching a Python gui instance via the Python Launcher.app supplied with OS X Pythons. You can verify that by selecting the .py file in the Finder and doing a Get Info on it. Python Launcher is a very simple-minded app that starts Python via a Terminal.app command. To directly launch your own Python GUI app, the preferred approach is to create a simple app using py2app. There's a brief tutorial here.
EDIT:
There are other ways, of course, but most likely any of them would be adding more levels of indirection. To make a normal launchable, "double-clickable" application, you need some sort of app structure. That's what py2app lets you create directly.
A very simple-minded alternative is to take advantage of the AppleScript Editor's ability to create a launcher app. In the AppleScript editor:
/Applications/Utilities/AppleScript
Editor.app in OS X 10.6
/Applications/AppleScript/Script
Editor.app in 10.5
make a new script similar to this:
do shell script "/path/to/python /path/to/script.py &> /dev/null &"
and then Save As.. with File Format -> Application. Then you'll have a double-clickable app that will launch another app. You can create something similar with Apple's Automater.app. But, under the covers, they are doing something similar to what py2app does for you, just with more layers on top.
Adding to the answer by Ned Deily, im my case when I tried to launch the Python application using an AppleScript application, it did not work initially. I discovered that it has something to to with some kind of encoding error (I am using UTF-8 and in the past I had felt need to configure it to UTF-8).
So, after further investigation, I discovered that I can accomplish this by creating an AppleScript application with the following code (adjusting the paths of python3 and of the Python application as needed):
do shell script "export LC_ALL=en_US.UTF-8; export LANG=en_US.UTF-8; /usr/local/bin/python3 '/Users/USER/FOLDER/SCRIPT.py' &> /dev/null &"
It launches the Python application without any Terminal windows. The AppleScript application can then be personalised with a custom icon as usual, and can be placed in the Dock. When clicked, it will launch the Python intepreter, that still shows up in Dock, but with no visible windows.
I think this may be useful to other users.
'console hide' doesn't hide the Terminal in OS X. It hides Tk's built-in console, which is really a relic from the MacOS Classic days (and which is still commonly used on Windows).