Make an exe file not showing a terminal - python

I am using "auto py to exe" to create an exe file from my python script. It works quite well, but it opens a terminal once I launch the script... How can I make it to hide / not display the terminal, like a daemon or a back-process?

Pass the --noconsole argument in the "Manual Argument Input" section. Otherwise, the option to do this should be somewhere there as seen here.

Related

.exe file opening Powershell Window

I made an .exe file using pyinstaller, but when I run the file it opens a PowerShell window as well. I was wondering if there is anyway I can get it to not open so I just have the python program open.
I haven't really tried anything as I don't really know what I'm doing.
When running pyinstaller be sure to use the --windowed argument. For example:
pyinstaller –-onefile myFile.py –-windowed
if you run it from terminal, you can use this command:
start /min "" "path\file_name.exe"

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

How to open a tkinter script that calls a different script within the same directory?

Sorry for the confusing question. I am working on a GUI and backend of a program that takes information from the gmail-api makes it into a text file. The back end and GUI(Tkinter) are working perfectly but through the python3 shell. When I just click on the python script within the directory a black command prompt appears and then disappears.
When I click on a prototype I have of the GUI that does not call another script but a text file, the GUI pops up perfectly.
This is after I used pyinstaller to make it an executable.
My end goal is to make the whole GUI and back end an executable file.
I was wondering if anyone knows why this happens. I think it might be because of it having to call another script...but I am not sure.
Sorry again for the confusing question and wordy explanation.
You want to go to the terminal after you've intalled pyinstaller and run this command:
pyinstaller --onefile --noconsole yourtkinter.py
Explanation:
--onefile : Optional here, more comfortable for tiny tkinter projects.
--noconsole : Will solve your command line opening issue.
Find here more about the pyinstaller package:
https://pyinstaller.readthedocs.io/en/stable/usage.html

Cannot run a Python file from cmd line

I have installed Python and written a program in Notepad++.
Now when I try to type the Python file name in the Run window, all that I see is a black window opening for a second and then closing.
I cant run the file at all, how can run this file?
Also I want to tell that I also tried to be in the same directory as a particular Python file but no success.
I assume you are running the script with command python file_name.py.
You can prevent closing of the cmd by getting a character from user.
use raw_input() function to get a character (which probably could be an enter).
It sounds like you are entering your script name directly into the Windows Run prompt (possibly Windows XP?). This will launch Python in a black command prompt window and run your script. As soon as the script finishes, the command prompt window will automatically close.
You have a number of alternatives:
First manually start a command prompt by just typing cmd in the Run window. From here you can change to the directory you want and run your Python script.
Create a Windows shortcut on the desktop. Right click on the desktop and select New > Shortcut. Here you can enter your script name as python -i script.py, and a name for the shortcut. After finishing, right click on your new shortcut on the desktop and select Properties, you can now specify the folder you want to run the script from. When the script completes, the Python shell will remain open until you exit it.
As you are using Notepad++, you could consider installing the Notepad++ NppExec plugin which would let you run your script inside Notepad++. The output would then be displayed in a console output window inside Notepad++.
As mentioned, you can add something to your script to stop it completing (and automatically closing the window), adding the line raw_input() to the last line in your script will cause the Window to stay open until Enter is pressed.
Try to open in Command Prompt instead of run window. The syntax is:
py filename.py
If it doesn't work, try to reconfigure Python. Did you set environment variables? If not, this could help you

Running Python from the Windows Command Line

How do I run a Python file from the Windows Command Line (cmd.exe) so that I won't have to re-enter the code each time?
Wouldn't you simply save your Python code into a file, and then execute that file using Python?
Save your code into a file called Test.py.
And then run it?
$ C:\Python24\Python.exe C:\Temp\Test.py
If you don't want to install an IDE, you can also use IDLE which includes a Python editor and a console to test things out, this is part of the standard installation.
If you installed the python.org version, you will see an IDLE (Python GUI) in your start menu. I would recommend adding it to your Quick Launch or your desktop - whatever you are most familiar with. Then right-click on the shortcut you have created and change the "Start in" directory to your project directory or a place you can mess with, not the installation directory which is the default place and probably a bad idea.
When you double-click the shortcut it will launch IDLE, a console in which you can type in Python command and have history, completion, colours and so on. You can also start an editor to create a program file (like mentioned in the other posts). There is even a debugger.
If you saved your application in "test.py", you can start it from the editor itself. Or from the console with execfile("test.py"), import test (if that is a module), or finally from the debugger.
If you put the Python executable (python.exe) on your path, you can invoke your script using python script.py where script.py is the Python file that you want to execute.
Open a command prompt, by pressing Win+R and writing cmd in that , navigate to the script directory , and write : python script.py
A good tool to have is the IPython shell. Not only can it run your program (%run command), but it offers also many tools for using Python interactively in an efficient manner (automatic completion, syntax coloring, quick access to the documentation, good interaction with Matplotlib,…). After you install it, you'll have access to its shell in the Start menu.
You need to create environment variables. Follow the instructions here: http://www.voidspace.org.uk/python/articles/command_line.shtml#environment-variables
In DOS you can use edit to create/modify text files, then execute them by typing python [yourfile]

Categories