python saving scripts problems - python

I am using Windows 7. I installed Python and everything is working fine except the fact that as I am saving python scripts on desktop or anywhere, none of them are opening.
.py files are closing in a blink!
.pyw files are not even responding.
Any help appreciated. I have already uninstalled and reinstalled the software suite but the problem still persists.
Here are the pictures of the icons.

What happens when you run a .py file is that a cmd.exe window is opened where Python runs your script. But this window will close as soon as your script finishes.
What you can do in this case:
Add raw_input() (python2) or input() to the end of your script to make it pause for input. That wat you can read any output before the window closes.
Open a cmd window and run your scripts from that.
With regard to .pyw files, they are themselves responsible for creating a window. So unless those scripts create a GUI you probably won't see anything.

Related

reroute terminal to interface of the application

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

Python IDLE 3.9.1 file not opening in windows

I had saved a python file after working on it for sometime, but now when I open it, Python 3.9.1 opens a window then immediately closes. I had done lots of work on this and don't want it to go to waste. I'm on Windows 10.
If you’re using the Open option when you right-click or you are simply double-clicking the script, the program will run and close so fast you won’t even see it.
Here are two options I use:
Open up the Command Prompt. You can easily do this by going to the address bar of your File Explorer and enter ‘cmd’. If you’re in the directory where your script is, the current working directory of the Command Prompt will be set to that. From there, run python my_script.py.
Edit your script with IDLE. If you’re using an IDE, it should be nearly the same process, but I don’t use one so I wouldn’t know. From the editor, there should be a method for running the program. In IDLE, you can just using Ctrl + F5.
Right click on it and clicken "open with". Then choose Python IDLE.
You are trying to run the file instead of editing it.
You have to right-click the file and you should the "edit with idle" option.

Pyinstaller .exe works from terminal but not by double-clicking -> flashing console window

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.

Pinning python application running through Python interpreter

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.

How to stop running Python .pyw script which doesn't have GUI window?

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.

Categories