Python Forum
.exe created with pyinstaller fails to execute
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.exe created with pyinstaller fails to execute
#1
Hi, I would appreciate some guidance as I am new to Python.
I have created a very simple programme ("tables.py" code included below)and compiled it using pyinstaller (using Windows 10 Powershell). That all seemed to complete successfully (The command and responses included below.)
The file "tables.exe" is created in the folder ...scripts/dist.
When I run it I get a pop up window that says "Fatal error detected", and "Failed to execute script Tables", and has a button labeled "OK", which just causes the pop up to go away.
I would appreciate any help anyone can give me as I don't have a clue what to do. Thanks,

Ian

PS C:\Users\Ian\AppData\Local\Programs\Python\Python38-32\Scripts> .\pyinstaller --onefile --windowed tables.py 91 INFO: PyInstaller: 3.6 91 INFO: Python: 3.8.2 91 INFO: Platform: Windows-10-10.0.18362-SP0 94 INFO: wrote C:\Users\Ian\AppData\Local\Programs\Python\Python38-32\Scripts\tables.spec 96 INFO: UPX is not available. 97 INFO: Extending PYTHONPATH with paths ['C:\\Users\\Ian\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts', 'C:\\Users\\Ian\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts'] 98 INFO: checking Analysis 237 INFO: checking PYZ 274 INFO: checking PKG 368 INFO: Building because C:\Users\Ian\AppData\Local\Programs\Python\Python38-32\Scripts\build\tables\tables.exe.manifest changed 368 INFO: Building PKG (CArchive) PKG-00.pkg 4074 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully. 4143 INFO: Bootloader c:\users\ian\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\runw.exe 4144 INFO: checking EXE 4160 INFO: Rebuilding EXE-00.toc because tables.exe missing 4161 INFO: Building EXE from EXE-00.toc 4162 INFO: Appending archive to EXE C:\Users\Ian\AppData\Local\Programs\Python\Python38-32\Scripts\dist\tables.exe 4179 INFO: Building EXE from EXE-00.toc completed successfully.

The code in "tables.py"

import random
print ("test your tables")
choice = input("Want to choose a table? y/n: " )
if choice == "y":
tablechoice = int ( input ("Which One? 1 to 12:"))
trials = 1
while trials < 100:
trials = trials + 1
if choice != "y":
a = random.randint(1, 12)
else:
a = tablechoice
b = random.randint(1,12)
print( "what is", a, "times", b, "?")
answer = int (input())
while 1==1:
if answer == a * b:
print ("well done")
break
else:
print ("try again")
print( "what is", a, "times", b, "?")
answer = int (input())
Reply
#2
Can you show us the pyinstaller command you used?

for example:
pyinstaller tables.py -n tables --onefile

I'm certainly no expert on Pyinstaller (or anything) but
it doesn't look like it's the usual problem of not finding
a module as random is a built in library.

So I'm guessing it's either something in your command, code or
your setup.

You need to format your code please. I did a quick format as I'm short of time
but I may have introduced bugs.
The exe runs until a bug is hit then cops out,
don't think it's pyinstaller, just a bug or two in your code probably.
[Image: Region.png]

import random

print ("test your tables")

choice = input("Want to choose a table? y/n: " )
if choice == "y":
    tablechoice = int ( input ("Which One? 1 to 12:"))

trials = 1

while trials < 100:
    trials += 1
    
    if choice != "y":
        a = random.randint(1, 12)
        b = random.randint(1,12)
    else:
        a = tablechoice
        b = random.randint(1,12)

    print( "what is", a, "times", b, "?")

    answer = int (input())

    while 1==1:
        if answer == a * b:
            print ("well done")
        break
    else:
        print ("try again")
        print( "what is", a, "times", b, "?")
        answer = int (input())
It works now but needs work on the program.

[Image: Region.png]
Reply
#3
Thanks for the response. The pyinstaller command was in the original message. it is
.\pyinstaller --onefile --windowed tables.py
Sorry about the code - here it is included properly. This runs with no issues under python.

import random
print ("test your tables")
choice = input("Want to choose a table? y/n: " )
if choice == "y":
    tablechoice = int ( input ("Which One? 1 to 12:"))     
trials = 1
while trials < 100:
    trials = trials + 1
    if choice != "y":
        a = random.randint(1, 12)
    else:
        a = tablechoice     
    b = random.randint(1,12)
    print( "what is", a, "times", b, "?")
    answer = int (input()) 
    while 1==1:
        if answer == a * b:
            print ("well done")
            break
        else:
            print ("try again")
            print( "what is", a, "times", b, "?")
            answer = int (input()) 
Reply
#4
sorry we uploaded the code about the same time lol.
Let me know if you sorted on this.

I think you should leave out the --windowed bit
that is for when using a gui I think.

try this it works:
pyinstaller tables.py -n tables --onefile

also the order can be important,
put the .py file name first,
then the exe filename,
followed by any params.

https://stackoverflow.com/questions/4066...er-to-open

I am out of time, i'll check later if you need any more help on this.
good luck.
Reply
#5
Steve, Thanks a million. I would never have got there from the pyinstaller documentation or the error messages.
I can send this to my grandkids now - I'm not sure they'll thank me!!
Ian
Reply
#6
Nice one Ian, good luck.


(Apr-20-2020, 03:09 PM)iankerr Wrote: Steve, Thanks a million. I would never have got there from the pyinstaller documentation or the error messages.
I can send this to my grandkids now - I'm not sure they'll thank me!!
Ian
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo exe created by pyinstaller only works in the dist directory dee 7 2,822 Feb-23-2023, 05:53 PM
Last Post: dee
  PyInstaller fails after changing 32 to 64 bit pynz 3 3,600 Nov-27-2019, 08:12 AM
Last Post: buran
  Pyinstaller with Sys.Argv[] - “Failed to Execute Script”? ironfelix717 0 5,321 Aug-07-2019, 02:29 PM
Last Post: ironfelix717
  Help with PyInstaller + Script "Failed to Execute Script" ironfelix717 2 9,573 Jul-31-2019, 02:18 PM
Last Post: ironfelix717
  Pyinstaller can not execute script. negru555 0 2,505 Jan-27-2019, 05:15 PM
Last Post: negru555
  Pyinstaller to execute a script in command prompt Ciroxxx 0 2,095 Sep-18-2018, 10:17 AM
Last Post: Ciroxxx

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020