I wrote a simple script in python 3.7 and I coverted it in .exe from cmd with the following line pyinstaller -w -F -i [myicon.ico] [myscript.py] . My script works if i launch it from command line (python myscript.py ), but it doesn't work when i click on "Myscript.exe" (I have a window with this message :"Failed to execute script Myscript").
I try to create the same script without the icon but result is the same.
Someone can help me?
You can refer to that post:
Windows- Pyinstaller Error "failed to execute script " When App Clicked
Actually the answer is that python doesn't compile the icon and so you need to manually transfert the icon in the folder containing the .exe.
B
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 a simple code with few "print" and "input".
I used cx_freeze to convert my python code on ".exe", but obviously when I launch my exe, it's run in background without any GUI (ofc I don't have GUI).
How to open it on cmd to interact with some "input" and see "print", like I do with my IDE (pycharm) cmd ?
Do you have to run it as an .exe, or is your goal to just run the script in cmd? To execute an .exe file in cmd, you should be able to just run by entering in the filename while you're in that file's folder directory:
Change to directory where program.exe is located by using cd:
cd C:\Users\johndoe\folder\
Run the program program.exe program.exe
However to save you compiling the python script to a .exe each time, if you already have python installed in your windows and you just want to run the python script, it should work with user inputs in the script by just entering python and the python filename (e.g. pyscript.py) into the windows cmd like below:
python pyscript.py
If your python script is a class / function that accepts arguments input1 and input 2:
python pyscript.py input1 input2
I have some python script which is having more number of .py files, So I have generated .exe file for that, and I am trying to run using command prompt. I am unable to run .exe file in cmd prompt but when I tried to run on my friends laptop it is working fine.
I tried in cmd like below:
C:\pythonworkspace\Verification.exe -i C:\pythonworkspace\kpi_verification_2.0\config\Verification_config.xml
getting error as below:
Cannot open self C:\pythonworkspace\Verification.exe or archive
C:\pythonworkspace\Verification.pkg
Please help me where it is going wrong.
I did a application with Python 3 using Tkinter gui, on Raspbian with the RPi. I have three questions:
1) I've turned the python script into executable using:
chmod -x path/myfile.py
I've declared on the first line of script
#!/usr/bin/env python3
When I double click onthe script it pops up a windows asking if I want to execute normally or on the terminal. If i chose Execute, the script runs normally.
Is there any way to execute normally directly, without asking?
2) How do i create a shortcut on my Desktop to execute my python script?
I've created a file on the desktop and I edited the following:
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Name of the shortcut
Comment=Comment
Icon=path/pic.gif
Exec=python3 path/myfile.py
Terminal=false
The picture if the shortcut works, but the script it's not launched. It appears the hourglass and nothing happens.
3) How do I make a python script launch when at the startup of Raspbian?
I've already edited the
/etc/xdg/lxsession/LXDE/autostart
and also the
/etc/xdg/lxsession/LXDE-pi/autostart
with:
#python3 path/myfile.py
on the last line of the file. Rebooting the system, nothing happens.
Thank you for your help.
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')