This question already has an answer here:
How to hide the python console window in Pyinstaller
(1 answer)
Closed 2 years ago.
I have a python script that is supposed to be running in the background. I used pyinstaller to create an executable file for the script. Now, this file opens up a terminal window. I don't have anything that is going to be printed on the terminal window, so I want it to close up just after starting up the process. How can I do that? Right now I just have a continous loop like this:
while True:
myFunction()
time.sleep(some-arbitrary-timeout-value)
Based on the context given, I will give you several options here for you to choose:
python pyinstaller.py --noconsole yourscript.py
You won't see the console window when executing your file.
nohup python your_executable.py & Keeps the script running even if you close the terminal
pythonw test.py similar to nohup, works on windows
you can launch your script and detach it from the terminal console by :
on linux you can use nohup & : nohup python your_executable.py &
on windows you can look at nohup on windows on stackoverflow
Related
This question already has answers here:
Run a shell script and immediately background it, however keep the ability to inspect its output
(3 answers)
Closed 4 years ago.
I have a script that I activate via the terminal that listens to events. I want to keep using the terminal after the script runs, but the script is running and I can't type anything. The only way I know that lets me keep typing is by using the Ctrl + C combination, but this stops the script.
So how can I run the script in the background and keep using the terminal without terminating it?
Edit: I tried to use the '&' operator but it didn't work:
You can run your script in the background with:
python myscript.py &
If your script does output something you can suppress the output with:
python myscript.py 1>/dev/null 2>&1 &
Or save the output for later:
python myscript.py 1>myoutputfile 2>&1 &
# ...
less myoutputfile
Another alternative would be to use for example screen or tmux.
This question already has answers here:
Run Python script without Windows console appearing
(11 answers)
Closed 5 years ago.
I am currently learning Python and I am working through a project in a book entitled Python Crash Course. The project involves developing a game called "Alien Invasion". In the process of running the game, it opens a 'window' area where the action occurs while keeping a command prompt shell open. At least to me, it seems tacky to have a command prompt shell open. I am thinking about developing some games and I want to have a professional look to them. Is there any way of automatically closing the command prompt shell close after a program compiled in Python has started?
If you are opening your program on IDLE, I believe it is not possible to not have the Shell window open as it is the main window for any sort of system output like errors. However, to make your game look more professional, you can use py2exe or py2app (Mac OS X). This will help you turn your program into an executable file that is also portable. Also, when you open your executable game window, there will be no Shell window opening.
I want to, from a python script, open a new terminal window.
Then, on that new window, run another python script, located on the same directory.
I needs to be on another window, because both scripts have while True loops, and I need them to run simultaneously.
How would I do that?
Thanks everyone!
You can just spawn an xterm with the python code used:
xterm -e "python /path/to/your/file.py"
This will close when the process ends.
If you need to, you can do this from inside a python script using the subprocess module (https://docs.python.org/2/library/subprocess.html).
This question already has an answer here:
Compile app with Pyinstaller, but do not launch cmd when running resulting exe
(1 answer)
Closed 10 years ago.
I am using wxpython to develop a GUI and I compiled it with pyinstaller. Everything works fine but there is always a black shell window pop up before it actually lunch the program. (Just like you use python instead of pythonw to run the script)
My question is, how to avoid that?
From: http://www.pyinstaller.org/export/v2.0/project/doc/Manual.html?format=raw#getting-started
-w, --windowed, --noconsol
use a windowed subsystem executable, which on Windows does not open the console when the program is launched.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I hide the console window in a PyQt app running on Windows?
I am programming under Python2.6 + PyQT + Eric4 environment.
All the GUI and Program parts are done, but here is the problem.
When I run my program, two windows pop up.
One is the window (or frame) I want, the other is like a python interpretor window having a all black undergroud color. And I really don't want this to show.
What can I do to get rid of it?
Please help me out of this.
I suppose you are using Windows, the only operating system I know to open a prompt when you double click a script. There are two solutions AFAIK: execute the file with the pythonw.exe executable, as suggested by #Adrien. If you save the file with the .pyw extension, Windows automatically uses pythonw.exe for executing the script when you double click
on windows, you can get rid of the console window by using pythonw.exe to run your script (instead of the standard python.exe)
(i don't know if there is a similar difference on other operating systems)
On Windows, the program window only pops up if you save your python file with the extension .py instead of .pyw.