I made a python script and it should run all the time on my computer but I want it to be hidden. How can I hide the console so that the user doesn't have to see it in his taskbar the entire time?
I cannot comment as < 50 rep :/
Save the python file as .pyw (This removes the console)
File will run without the console 'hiding' it
Close it by using Taskkill or task manager
EDIT
If you want the program to launch on start up, put a shortcut or the file in the startup file
To get there go to run (Window + R)
and type shell:startup
Copy your file into the directory
If you're on windows or any os you can try this
from editor jump to file >> save as >> yourname.pyw ... then you can run the saved file
what this will do ??
it will basically hide the little noisy terminal/cmd windows ..that's it :)
it will be better if you tells us what op your're on .
Related
I have a .py file open in Visual Studio Code. However, I'm missing the jupyter notebooks functionality to execute cells/debug. Is there any way I could execute and debug single parts of the whole .py script?
It would be great if you could specify exactly what you mean by missing the jupyter notebook's functionality, because you could use the #%% magic line depending on the kind of limitation you have.
If your need is just to run code line by line or by chunks you can do so using VS Code quite easily. You just need to have a terminal window open, select the part of the code you want to run, and press ⇧ + ↩(Mac). Maybe your key binding is different, but you can check it on Preferences: keyboard shortcuts under Python: Run Selection/Line in Python Terminal
You can bebug the file by placing breakpoints in it, and then copy & paste portions of the file into the DEBUG CONSOLE to execute them (or press continue, etc.).
https://code.visualstudio.com/docs/python/python-tutorial
I want to open a python file in cmder terminal quickly. Currently, the fastest way i know how is to navigate to the directory of the python file in cmder terminal and then run it by calling "python file.py". This is slow and cumbersome. Is there a way for me to have a file or exe, that, when i run it (or drag the program onto it), automatically makes the program run in cmder straight away.
Windows 10
Clarification: I'm using cmder terminal specifically because it supports text coloring. Windows terminal and powershell do not support this.
On windows you can go to the directory with the file in the explorer and then simply hold shift as you right click at the same time. This will open the menu and there you will have the option to use the command shell/powershell and then you don't have to navigate to the directory inside the shell anymore and can just execute the python file.
I hope that helps.
Answer: The escape codes just weren't properly configured for the windows terminals. You can get around this by using colorama's colorama.init(). It should work after that.
How to associate .py files to open CMD with py then the filename? Maybe in a .bat file?
sorry about my poor English, and if I insist on subjects you already master, it's my first constructive answer here ;p
I'm not sure about what you want to achieve but from your question and its tags I assume tha you want to :
run ".py" file containing a python script from the file explorer by double clicking it
have a cmd.exe window open after this action with your python script interpreted
have a way to review this scipt output without relying on superman eyes able to gasp 65536 characters per millisecond
So basically, if you have a script printing "Hello World !", you want to click on it, and see in a cmd.exe window the text "Hello World !" displayed to validate that your script is working properly ? To make it short you are RIGHT, a .bat file will be enough to do the trick, even if there is a whole bunch of alternatives including executable generation to embed a full python interpreter (see http://www.py2exe.org/), or simply adding a wait loop at the end of your script, but having a batch script associated is probably the lightest and easiest solution in your case.
As you figured out, associating .py files with the python interpreter will run your scripts but the console window will dissapear immediatly on completion without letting you the time to consider the output. You just need to associate .py files (right click -> open with, if you want to do it programatically it's possible to set this in the windows registry) with a .bat script that will do the job, that is, run the script and wait until you are ready to "leave".
This batch script will take the python script you clicked on as an argument, run it with your python interpreter and pause it's execution, waiting for your input before leaving. Since the default windows file association will execute your target program and pass it the file executed (should it be a click or a "start XXX" command) it's pretty straightforward, the bricks to do this in batch are :
program_name argument : to directly call an external command, so "python my_script.py" will run the python.exe program (no need to add the ".exe" or "'.com" part since it's an obvious case for windows) with my_script.py as argument, provided that your python executable directory is in your PATH environment variable, otherwise you will have to provide the full path, ie: "C:\Python27\python.exe my_script.py" .
%X : to reference command line arguments sent to your script (%1 for the first one, then %2 etc.,)
pause : a command that will display the message "Press any key to continue ...", and obviously wait for any key before leaving your script
evantually, #echo off : to avoid printing each batch command before its execution
So, assuming that your python interpreter is installed in C:\Python27 (please replace with whatever version / location for your python.exe, or just "python" if it's in your PATH) your batch script could look like something like this :
#echo off
C:\Python27\python.exe %1
pause
Save it somewhere, associate it with .py files, and you are done. HTH
You can do it in two separate ways:
First, you can rename your .py file to .pyw and just open it and the script would be executed immediately (with pythonw.exe) but this is not showing you a console output.
Or you can simple associate your .py files with standard python.exe which will show the console output.
We are using Ubuntu for OpenERP development, everyday at morning I have to browse to openERP directory from terminal, start the "openerp-server" python file with lots of parameters, and then keep the terminal window open.
Is there a way that I can double click a python file on desktop which will start the following file with its parameters from its own directory ?
The directory I use right now to start the program is "home/username/Projects/openerp_7_0/server/"
after navigating to this path in terminal I enter:
"python openerp-server --addons-path=../addons "
So how can I create a shortcut for this on desktop.
Rather than “double clicking a python file on desktop” you could put a shell script on the desktop (and single click to start, not double click), somewhat as follows.
#!/bin/sh
cd $HOME/Projects/openerp_7_0/server/
/usr/bin/xterm -e 'python openerp-server --addons-path=../addons; /bin/bash' &
(Alternately, say /usr/bin/gnome-terminal instead of /usr/bin/xterm.) The ; /bin/bash part may be unnecessary if the openerp-server runs indefinitely. Include the ; /bin/bash part if you want the terminal to remain (and display any output) when openerp-server finishes; don't include it if you want the terminal to go away when openerp-server finishes.
Although I would recommend trying to import the python file and then running it that way, I get the feeling that in this case you can't.
So you could try something like this.
import os
os.system('python /home/username/Projects/openerp_7_0/server/openerp-server --addons-path=../addons')
I am trying to open a file through python that once it is open takes you to a GUI. The link works fine when i just click on it and python seems to locate the file and open it, but the GUI doesn't appear. Please help. This is whay i have been using.
import subprocess
subprocess.Popen("C:/full/path")
I get no track back errors, but the GUI doesn't appear. Thoughts of how I can get it to appear, or what the problem might be?
Thanks
The file you're trying to 'start' is a cmd script. Use this code:
subprocess.Popen("cmd.exe /k C:\full\path\to\file.cmd")
.cmd files are not executable by themselves - you need to invoke cmd.exe to execute them. This is also what windows does when you double-click the file on the desktop.