Getting pyinstaller .exe program to run from clicking file? - python

I have a command line based program that I've turned into an executable using PyInstaller. I would like the program to launch a command prompt and run when clicked. Currently I can only get it to run from the command prompt. When I click it, a blank command prompt will open, remain open for a couple of seconds and then close. I'm stuck. Does anyone have any suggestions?

Have you tried the --console flag with pyinstaller?

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"

How to properly close Python exe console program

I'm trying to figure out how to do exit if the program is done with it's work.
What should I use?
I've tried:
sys.exit()
and
os._exit(0)
But none of them worked in exe created by Py2Exe. It works when it is runned as a py script but if I create an exe, those exit commands do nothing.
Use: quit()
In python's command prompt
Use pyinstaller instead of py2exe you will love it :). sys.exit() should work on pyinstaller.
to install
python -m pip install pyinstaller
to build exe in single file
pyinstaller yourscript.py --onefile
to build a gui app w/o console
pyinstaller yourscript.py --noconsole
If you have problem using pyinstaller dont hesitate to ask :)
If you are just using a console window, it will automatically close at the end of your program.
print("Hello World")
input()
If you run the .py file, a terminal window should pop up that says hello world. When you hit enter(the input part) the program will look for another line of code and when it finds none, will close the program and console window.
If you are trying to execute a command from cmd on python just add \c to the command, and it will close after its execution
example os.system(r'cmd /c "C:\Program Files\PATH" -file C:\PATH.exe')

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

Command prompt closing too quickly

I know there are lots of questions on this topic, however none so far is the result of a pyinstaller package.
I used pyinstaller to package a python file. It runs well before packaging, but when I open the exe, it briefly displays an error and closes before I get the chance to read.
How can I stop the command prompt from doing so, or how else can I view this log?
Manually open a command prompt (Start > Run > cmd), navigate to the folder containing your program (cd C:/Users/Ladmerc/python_programs), and then run the program (my_program.exe). The terminal window will stay open after the program exits.
You can always open the command line and then run the executable from there. I'm sure there are other ways, but this is the first that I thought of. Here's a link that may be helpful.

Converting .py to .exe in python 2.5: doesnt execute .exe program directly

I have successfully converted my .py script to .exe but the problem is that it wont get executed when I press the .exe icon. A black screen pops up for a fraction of a second and then disappears.
I tried executing it through the command prompt and it did get executed but doesn't run if I click the .exe directly. Just want to know if there is some error in placing the .exe file due to which I am encountering this problem.
# setup.py
from distutils.core import setup
import py2exe
setup(console=["myscript.py"])
python setup.py py2exe --help
python setup.py py2exe
Your shell disappears because the program finishes.
End your program with a raw_input('enter to finish') line and the console will stay allowing you to see the result.
How do you know it got executed when you ran it from command prompt? If the app just outputs something and exits, you will see the behavior you are describing: the black window will flash and disappear. That the same as running any other win32 console app from windows explorer.

Categories