Pyinstaller executable not running - pyinstaller

I made a small application using Python and Tkinter and I then tried to convert it into an executable file using Pyinstaller.
Pyinstaller creates the executable in the folder 'dist' as expected but when I double click on the file it will not run. Can you please help me find out what I am missing?

When this happens to me.. I use the process of elimination to discover the cause.
Simply remove modules from your code until the program execution actually begins. You can detect if you code is running by putting a dbgview output statement at the top of your code. Once your code execution works... you'll know what module or section of code is the root of the problem with regard to pyinstaller.

Related

I am trying to convert a python .PY file to .EXE. But the EXE file won't run because of "Fatal Error Detected Failed To Execute Script Error" Help Pls

I am a absolute beginner with Python. What I have done so far is I have installed Python with IDLE, Pycharm, Pygame-zero and Pyinstaller too. I have a (.py) file game I would like to turn into a (.exe) file. So I can release my game for my friends to play.
I have entered this command into CMD window "pyinstaller --onefile -w gamename.py"* (*My game is not really called "gamename". I have called it that in this code above. For this example only.)
When in the file folder of my game and then Pyinstaller converts my file into the (.exe) file. But everytime I try to run this file. It fails with this error message - "Fatal Error Detected, Failed To Execute Script Error".
I have watched all kinds of YouTube videos trying to solve this problem and have tried these following fixes:
Updated Pyinstaller (4.3).
Updated Python (3.9.5).
Changed the path in Enviroment Variables to point to Python39\Scripts and resetting my computer.
Coverted the (.py) file to (.exe) by including the console window. Then after running the program after when the console window disappears. Opening the CMD window again and typing the file directly "gamename.exe" to run.
Installing auto-py-to-exe program.
Each time deleting the Main, Dis and Spec files and moving the (.exe) file into the main file folder. With the resources for the games. Music, Images and Sounds.
Testing out my Python script to check. If it doesn't have any errors while loading through IDLE and it doesn't. It works straight away, I can play my game through IDLE. There is no errors in the code of my game script.
And after trying all of these solutions it still hasn't solved this issue.I still have the same error message appearing when trying to run my game. Now I have found out what the meaning is to this error message that appears. Which is:
"Fatal Error: failed to execute
This means something has gone wrong as it's giving you a visual warning about it; this is not an error, it's a warning; the real error has been printed to stdout/stderr. If you open the executable using the terminal or something else that will preserve the console output, you will most likely see a Python error telling you what went wrong. Fixing this and repackaging is the solution to this issue".
I have remade the (.exe) file including the console window and it does explan what the error is. When I try to run my game, the error comes up as:
"FileNotFoundError: {Errno 2} No such file or directory: C:*****\Local\Temp_MEI58602\pgzero\data\icon.png {4268} Failed to execute script.
Any suggestions? On how to fix this error please. So I can run and play my game outside of Python on any PC.
A Possible Answer:
I have found a webpage that has the possible answer to my problem. But I don't know what they mean, because I am a beginner with Python. Can anybody read this and break it down for me? Here is what it say's:
"Pyinstaller packaging exe, missing icons and other issues
Reason
When the exe runs, it will decompress a resource folder named "_MEI*" to a temporary directory on the computer, and delete it when the program ends.
uses a path like ‘\icon.png’ in the program. When the exe is running, it will only search for its own directory, of course it cannot be found.
Two, the solution
Make sure the picture is in this temporary resource folder
This can be done by editing the'.spec' configuration file to add pictures.
(Note: .spec is the file generated by Pyinstaller last time, in your python project directory.)
These are the three pictures I used, which is actually adding three tuples to the "binaries" list
Before the comma is the address of the picture in the python project, after the comma is the address of the package into the ‘_MEI*’ temporary folder.
I have built an ‘img’ folder to store pictures in it. Just put a dot in the root directory, such as (’./img/info.png’,’.’)
Finally, run when packagingpyinstaller program entry.spec, You can add the picture resource.
(Note: Other external resources can also be added in this way, such as .ini, .txt, .exe, etc.)
Make sure the program can find this path
Because the name of the temporary directory is different each time, a method is needed to dynamically obtain this path.
The code is presented, and the core statement is ‘os.path.realpath(sys.path[0])’.
Python running effect is as follows:
Package it as an exe, drag it to the cmd window and run it."
Here is the link to the webpage to the article. Because it makes use of screenshots that I can't include on this webpage;
(https://www.programmersought.com/article/94965073850/)
Please read this acticle and break it down for me. It does seem to be explaining the solution to my problem. But what does it all mean? What pictures is he talking about? Please explain.
I am not sure why but PyInstaller doesn't seem to bundle everything needed for Pygame Zero, including that icon.png file. The solution is simple, though. You just need to use pyinstaller --collect-all pgzero --onefile -w <scipt_name>. If your game has sounds, images or anything like that, remember to include those specific folders as well using --add-data <file_or_folder>. Also, make sure your script includes the following lines.
import pgzrun
# GAME CODE HERE
pgzrun.go()
I hope it helps, even though it is a little late.

RobotFramework RIDE cannot import library

I have a file right here: Library ../../MyLib/My_Lib.py, and I try to import the python file in RIDE, but RIDE still report "FAIL : No keyword with name '****' found", and this keyword is defined in the My_Lib.py, seems RIDE cannot find the python file.
I using python 2.7.8+Robot Framework 3.1.2+windows server 2012r2. I even selected Library -> Name -> Browse in RIDE, but the error still there and this whole robot test case folder is copied from another server which is working fine
Can anyone suggest what have I missed?
Ah! I have worked this out, if anyone else meets the same issue, you can click Tools->view RIDE Log, to see what's happening there. For my case, it's because I didn't install thrift but the My_Lib.py obviously used thrift module, so the My_Lib.py compile failed with "No module named thrift.Thrift".
Is it possible the Python library was created to work with Python 3.x.x leading it to not work on your Python 2.7.8? See https://wiki.python.org/moin/Python2orPython3
Check what python version is being run on the other server where the test is running fine. You might need to update your local Python version.
Also, you could try running the Robot test outside of RIDE just in case. You may do so by navigating to the test folder where the .robot file resides and running the following command:
robot test_file_name.robot
See if you get the same error that way. Please report back after doing the mentioned checks and we can continue debugging, my reputation doesn't let me comment on your question so I will just update the answer as we go along.

Omnet++ Simulation failing to run makefile

I'm currently an undergraduate researcher and I've been tasked with researching knowledge defined networking. The research in particular deals with very advanced code that's way beyond my minimal knowledge of omnet. The first instruction to build the network is to run the makefile (found here: https://bpaste.net/show/d26a592a563a) to generate the "networkRL" needed by the python script.
I've imported all of the files needed for the simulation but whenever I try to run the makefile I get an error:
"Error starting process.
Cannot run program "C:\Users\Sierra\DRL\omnet\router\makefile": Launching failed"
Or when I try to run the entire simulation it asks:
"Enter parameter 'NetworkAll.node0.tcontroller.folderName':"
I'm not sure if these are simple problems to solve and I'm just inexperienced, but any help would be greatly appreciated. I can post all of the source, ned, and header files if necessary. I didn't want to pack this entire post with 15+ code links if the makefile was the only one needed to solve this issue.
I'm using OMNeT version 4.6 on Windows 10 if that information is relevant
The term "run the makefile" means: run make in the directory where makefile is located. In OMNeT++ one can do this in two ways.
First way:
Open mingwenv.cmd from OMNeT++ main directory.
In the mingw console go to main directory of the project, for example:
cd /C/Users/Sierra/DRL/
In the mingw console type:
make
Second way:
In OMNeT++ choose File | Import.. |Existing Project into Workspace and select the project.
Build the project choosing Project | Build Project.
According the second error: open omnetpp.ini and set value for folderName parameter, for example:
**.folderName = "/c/some/directory"
or
**.node0.tcontroller.folderName = "/c/some/directory"

Can I get source code from PyInstaller generated package?

Seems the PyInstaller put all the python script into the executable file, and when run this file, it start PyInstaller bootloader first, then prepare a temp python environment add run the scripts.
So I wonder whether my source code are safe. Can I get the source code from the package when running the executable file?
PyInstaller includes the byte compiled (.pyc) files of your program but not the original source (.py) files. You don't even need to run the executable to get the .pyc files. There are more or less working Python decompilers that turn compiled byte code (.pyc) into equivalent source code (.py).
You need to assess whether this protection is good enough for your purposes. However as a friendly suggestion, I recommend first inventing/writing something that people will want to copy before worrying about how to protect it.

Building Brackets Shell (After running the grunt build command)

On windows after running the grunt build command for creating brackets shell it gives done without errors but i dont see any .exe file generated..
What might be the problem???
Here are some possible solutions:
Are you following the full brackets-shell build instructions, including all prerequisites?
Make sure Brackets isn't running at the same time. The build will fail silently if the .exe file is currently in use (see bug).
Try with a fresh git clone of the repo. If your brackets-shell local copy has been around for a while, sometimes the build & deps folders can get in a bad state. (I'm assuming you haven't modified the source at all. If you have, try with an unmodified copy of the source first to make sure it builds correctly without any of your changes).
Check that python --version shows 2.7.x
Verbose build output would also be helpful in diagnosing issues like this, but unfortunately there's not yet an easy way to get that...
If you follow the instructions on bracket-shell's wiki page, the Windows executable should be created in the Release directory.

Resources