I created a python file where an event loop is running.
During this event loop, pressing certain hotkeys causes interaction with another app.
If I open the file and run it through PyCharm, it works.
If I run the file in a terminal or as a .py file, the code exits prematurely for some reason so I have to run it with the python -i command or add input() at the end of the code so that the event loop keeps running for the hotkeys to work. Is there a reason why that happens?
Now I would like to autostart this file every time Windows runs. In theory it should be easy:
Change it to .pyw and run it with pythonw.
However, if I do that and click on the file to execute, it doesn't work. No idea what is happening in the background.
If I run the file in a terminal like this: python main.pyw
the script is executed in the terminal, I can see it and the hotkeys work.
Why is .pyw not working for me here? What other alternative do I have to run the file in the background so that I can always use the hotkeys whenever I boot Windows?
Related
I'm trying to run an executable file called CDQ.exe (which is supposed to create a text file) from within a python script. I'm using os.system(CDQ.exe) to run it. When I start the python script, the program freezes upon the os.system() call. I also don't get the text file. When I opened the task manager, I found CDQ was still running, and it kept running until I ended it.
When I try to run the CDQ.exe from the windows file browser by clicking it twice, the program appears for a couple of seconds in the task manager, then it closes, and my text file appears.
The executable file was created from c++ qt, and I'm using windows.
Does anyone know what's going on?
I have created a Python script for which I don't want to see the console pop-up every time it's being ran. I tried the pythonw.exe + .pyw approach, and while the script works just fine, the console still pops-up regardless.
.bat file content:
"C:\Users\mariu\anaconda3\pythonw.exe" "C:\Users\mariu\test.pyw" pause
And this is the inevitable console:
Is there something am I missing?
I had the same issue and moved to powershell script, since my tasks needed to start in parallel, and batch script seems not to behave like that, even with pythonw.exe
A .ps1 with the lines below should do the work
& "C:\Users\mariu\anaconda3\pythonw.exe" "C:\Users\mariu\test.pyw"
exit
I have written a python program that periodically runs with ApScheduler package. The .pyw file runs in the background, but when I restart the PC the program doesn't continue running.
What can I do to run a code automatically in startup a windows 10 pc?
You should consider putting your python file to the Startup folder.
Click Win+R at the same time on your keyboard
Type shell:startup
Drag and drop your python file onto the folder that opened.
Note: I reccomend to put a shortcut of your python file for easier editing.
I wrote this bat file to run a program i wrote in python
#echo off
python C:\Project\myProg\main.py
pause
but nothing happens, when i click it twice just open closes nothing runs.
If I open a cmd and type just python C:\Project\myProg\main.py it works and runs.
I tried to Run as Administrator, but I get the same result.
Any ideas?
Is it possible to make a program in Python that, when run, does not actually open any window (including command prompt)?
For example, opening the program would appear to do nothing, but in reality, the program is running in the background somewhere.
Thanks!
Are you running the python program by double clicking *.py file in Windows?
Then, rename the *.py file to *.pyw.
Run it with pythonw.exe instead of python.exe.