I have a python (3.6) script prints the output using print() command:
print(convert_size(logsize))
Then I converted the script to .exe using cx_Freeze 5.0.1. When it does work from IDLE and prints the output, launching .exe file with double-click, or as Administrator, or executing it from cmd as Administrator doesn't produce any output at all: http://prnt.sc/emz5m4
I have tried to add input() at the end of the script and then re-compile the file to .exe, which supposed to "stop" window from closing but it still closes.
Does this happen to you only when compiling this script, or also with other scripts?
If you can't manage to get outputs into a console with cx_Freeze, maybe you can try compiling with pyinstaller. Specifically, the options '--console' or '--noconsole' will give you control over whether a console opens or not to see the outputs. It has worked fine for me.
https://pythonhosted.org/PyInstaller/usage.html
It appears the pyinstaller has been launched from 3.6 location since I had it installed for 2.7 and 3.6. Once the correct location (C:\Python27\Scripts) has been pointed to, the script has been compiled successfully!
Related
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"
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
I have written the following code in python 3.8
import os
log=open('userlog.txt', 'a')
log.write(os.getlogin())
log.write('\n')
log.close()
os.system('shutdown /s /t 0')
It works perfectly as intended when I run it normally: it adds the username to a text file and then shuts down the computer. However, when I use pyinstaller to convert it to exe it does not work. Instead, it opens up blank command prompt windows that cannot be typed in around once a second. Any reason that this could be happening?
I am using windows 10.
Compiling your script on Windows 10 with Python 3.6 and PyInstaller 3.6 worked for me. You might be compiling it incorrectly. For me, the following steps worked in Command Prompt (note that %USERNAME% is your username).
cd "C:\Users\%USERNAME%\path\to\script\"
pyinstaller script.py
The first step involves changing your current working directory to the directory containing your script. The second step is just the regular PyInstaller compilation process.
If that doesn't work check the output of the PyInstaller compilation and/or any error logs from PyInstaller. That might help you find the problem.
I use the Windows version of Python. I have a Python script using Pyside (nothing complicated, a kind of "hello world").
When I click on my script file or if I launch it from a command line, it executes perfectly and I have a GUI appearing.
However, I would like to avoid having a GUI if the script is launched from a textual terminal (cmd.exe, cygwin, ...). A kind of script which automatically knows if it should have a GUI output or a textual output.
Is there an easy and simple way to do that? I want to be able to do that with the Windows version of Python (not the one coming with Cygwin packages).
An obvious way would be to add a kind of "--no-gui" parameter when I launch the script from a textual terminal, but I wonder if Python (or some Python libraries) already provide tools for that.
Moreover I have an SSH server (Cygwin-base) on this computer, I can execute the script at distance but no GUI appear (of course) and I have no error message. It is a case where it is very interesting to know if the script failed because of the lack of Windows graphical support or if the script should adapt its output for a textual terminal.
I know that you can run file as .py file or as .pyw file. The second option is used for GUI applications and it does not open the console window. To distinguish these to two cases you can check isatty method of sys.stdout.
import sys
if sys.stdout.isatty():
# .py file is running, with console window
pass
else:
# .pyw file is running, no console
pass
EDIT:
I tried to run that with putty+ssh on linux box - it returns True.
I tried to use msys bash shell on windows box - it returns True (.py file)
I tried to use cygwin bash shell with cygwin python - it returns True (.py file)
Unfortunately, I have no possibility to try putty + windows cygwin ssh server.
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.