简体   繁体   中英

Pyinstaller exe failed to execute script

So this is my code, I can run it on my computer. As soon as I move it to another computer via flash drive, and try and open it, it reads failed to execute script. I used Pyinstaller with the commands for -w -F -i.

I've tried on two other computers aside from my own, it works on mine, but not on others. Please help!

from wand.image import Image as wand_image
import re
import os
import Tkinter as Tk
from ttk import *
import tkMessageBox
from datetime import datetime
import threading


total_files= 0
files_finished= 0


root = Tk.Tk()                                                                 #Starts the GUI.
root.resizable(False, False)


canvas= Tk.Canvas(root)
canvas.pack(fill=Tk.BOTH, expand=1)
canvas.config(width=500, height=125)
canvas.create_rectangle(0,0,500,500, fill="blue")
canvas.grid(row=0, rowspan=30, columnspan=100)


current_update= Tk.Label(root, text="... Activity Feed...", font="-weight bold", background ="cyan", width=49, height=2, border=0)
current_update.grid(row=4, column=0, columnspan=100)


current_update_display= Tk.Label(root, font="-weight bold", background ="black", foreground="white", width=49, height=2 , relief= "sunken", \
    text="0 out of 0 files completed.")
current_update_display.grid(row=5, column=0, columnspan=100, sticky="N")


Progressbar= Progressbar(length=495, maximum=0)
Progressbar.grid(row=6, rowspan=30, columnspan=100)


def get_total():
    global total_files
    for folder in os.listdir(os.getcwd()):
        if not os.path.isdir(folder) or re.search('zzz-Files Without Dates-zzz', folder):
            continue
        for filename in os.listdir(folder):
            file_type= re.search(r"\.\w+", filename)
            if file_type==None:
                continue
            else:
                file_type= file_type.group()
            new_filename= "%s%s" % (re.sub(".pdf", "", filename), " -converted_page.png")
            if not re.search(".pdf", filename) or re.search(" -converted_page.png", filename) or os.path.exists(r"%s\%s" % (folder, new_filename)):
                continue
            elif re.match(r"%s \d{6}%s" % (folder, file_type), filename) or re.match(r"%s \d{6} \(\d+\)%s" % (folder, file_type), filename):
                try:
                    possible_date_code= re.search(r"\d{6}", filename).group()
                    possible_date= datetime(month=int(possible_date_code[:2]), day=int(possible_date_code[2:4]), year=int(possible_date_code[4:])+2000)
                    if possible_date<datetime.now():
                        continue
                except ValueError:
                    pass
            total_files+=1
    Progressbar.config(maximum=total_files)
    current_update_display.config(text="%s out of %s files finised." % ("0", total_files))


def convert():
    global total_files, files_finished
    for folder in os.listdir(os.getcwd()):
        if not os.path.isdir(folder) or re.search('zzz-Files Without Dates-zzz', folder):
            continue
        for filename in os.listdir(folder):
            file_type= re.search(r"\.\w+", filename)
            if file_type==None:
                continue
            else:
                file_type= file_type.group()
            new_filename= "%s%s" % (re.sub(".pdf", "", filename), " -converted_page.png")
            if not re.search(".pdf", filename) or re.search(" -converted_page.png", filename) or os.path.exists(r"%s\%s" % (folder, new_filename)):
                continue
            elif re.match(r"%s \d{6}%s" % (folder, file_type), filename) or re.match(r"%s \d{6} \(\d+\)%s" % (folder, file_type), filename):
                try:
                    possible_date_code= re.search(r"\d{6}", filename).group()
                    possible_date= datetime(month=int(possible_date_code[:2]), day=int(possible_date_code[2:4]), year=int(possible_date_code[4:])+2000)
                    if possible_date<datetime.now():
                        continue
                except ValueError:
                    pass
            with wand_image(filename=r"%s\%s" % (folder, filename),resolution=300) as source:
                images=source.sequence
                wand_image(images[0]).save(filename=r"%s\%s" % (folder, new_filename))
                files_finished+=1
                current_update_display.config(text="%s out of %s files finised." % (files_finished, total_files))
                Progressbar.step(1)
    root.destroy()


for interval in range(2):
    if interval==0:
        thread_object= threading.Thread(target=get_total)
    else:
        thread_object= threading.Thread(target=convert)
    thread_object.daemon = True
    thread_object.start()


root.mainloop()

These are general things you might or might not have thought about:

  • Pyinstaller need to have the same type of system to deploy to as the system you are building on. If you are building on a 64 bit platform then you can deploy to a 64 bit platform. A 32 bit platform build will deploy to 32 bit platforms.

  • So you have path statements that are to the libraries on your computer but those don't exist then you have to bring them with you in the spec file .

I would suggest doing a one directory install rather than a file install for the first attempt, it's slightly easier.

Alright well I ran pyinstaller without -w so the command prompt would still open.

I ran it and got

ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.

So for whatever reason it still requires that even after it was made into a exe. So the new device needs it as well, odd but oh well.

This is now a new issue so I'll move on from here, but now I know. Thanks to everyone who read and commented!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM