How can I make a python program run in the background?
I don't need the console running since all it does is sends me emails with updates once an hour.
Is there a way to do it when I convert it to exe using py2exe?
I am using python 2.7.8.
Also, is there a way to make it open in the boot menu immediately when the computer turns on from the code?
Thank you
If you are asking strictly how to hide the console as part of the py2exe bundling, that's simple. See - Hiding command-line dialog in py2exe
If you are asking how to have a program without a GUI, just build the program in py2exe as above and run it. Unless you have created a GUI, it will run on it's own until it terminates or is terminated.
Related
I have made a GUI for my application. All scripts are in Python (2.7) and the GUI is created with Tkinter. I work on Linux, but I needed this app to be executable on Windows. So I've used py2exe, to create an executable. After a while it is working almost perfectly, but I have the following problem:
Somewhere in the application, I need to call external programs, namely ImageMagick and LaTeX. I use the commands convert, pdflatex, simply by importing os module and running os.system(build), where build = 'convert page.pdf page.gif'etc. When those commands are called from the *.exe application the console pops up (meaning a console window opens up for a split of a second and closes again). Is there a way, to prevent this behaviour?
It does not interrupt the application, but it is ugly and not a desired behaviour.
[Note] I chose not to add any samples, since there are lots of files and other content, which, I think, is not related to the problem. I could however try to post minimal (not)working example. But maybe it is not needed.
Thanks!
import subprocess
subprocess.Popen("application.exe", shell = True)
I'm just wondering (as im starting to make a game with pygame) is there a way to 1) Run a program that only opens a GUI and not the shell
and
2) Run the program without having to edit with idle (I'd like to do this so the game will look more professional.
I would like to just have a desktop shortcut or something that when clicked, runs only the GUI and doesnt show my code or show the shell.
If you're on windows, a quick thing could be to make a one-line batch script.
start pythonw.exe <filename>
The start keyword causes the shell to not wait for the program to finish.
pythonw vs python prevents the python terminal from appearing.
If you're on linux/mac, you could do the same with shell scripts.
I am a security student first starting out with Python. I've built my first program for my class and it is meant to be an exe so that it may run on any computer without having me install python onto it. The program is meant to go unnoticed by the user, but whenever it is executed a command windows pops up.
Does anyone know how to make a .py into a .exe that when launched would not bring up the command prompt?
I have already tried compiling a .pyw into a .exe and it still pops up the command prompt.
Googling around the py2exe web site, you need to say setup(windows=['myapp.pyw']) instead of setup(console=['myapp.py']). I have problems finding out which page is saying that exactly, but hints are given here for example (search for "console"):
http://www.py2exe.org/index.cgi/FAQ
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 would like to write a python script that will finally be converted to .exe (with pyinstaller lets say) and added to windows startup applications list. This program (once launched) should 'monitor' user and wait until user will start a specified program (say program1.exe) and then my python program should launch another specified program (program2.exe).
I know that there is something like subprocess to launch another program from python script but I was not able to make it work so far ;/ And as it comes to this part where I need to monitor if user does start specified program I have no idea haw to bite on this. I don't expect a complete solution (although it would be very nice to find such ;p) but any guides or clues would be very helpfull.
For the monitoring whether or not the user has launched the program, I would use psutil: https://pypi.python.org/pypi/psutil
and for launching another program from a python script, I would use subprocess.
To launch something with subprocess you can do something like this:
PATH_TO_MY_EXTERNAL_PROGRAM = r"C:\ProgramFiles\MyProgram\MyProgramLauncher.exe"
subprocess.call([PATH_TO_MY_EXTERNAL_PROGRAM])
If it is as simple as calling an exe though, you could just use:
PATH_TO_MY_EXTERNAL_PROGRAM = r"C:\ProgramFiles\MyProgram\MyProgramLauncher.exe"
os.system(PATH_TO_MY_EXTERNAL_PROGRAM)
Hope this helps.
-Alex