Pyinstaller exe 无法执行脚本

Pyinstaller exe failed to execute script

这是我的代码,我可以在我的电脑上 运行。一旦我通过闪存驱动器将它移动到另一台计算机并尝试打开它,它就会显示无法执行脚本。 我将 Pyinstaller 与 -w -F -i 的命令一起使用。

除了我自己的电脑外,我还在另外两台电脑上试过,它在我的电脑上可以,但在其他电脑上不行。请帮忙!

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()

这些是您可能想过也可能没有想过的一般事情:

  • Pyinstaller 需要部署到与您正在构建的系统相同类型的系统。如果您在 64 位平台上构建,则可以部署到 64 位平台。 32 位平台构建将部署到 32 位平台。

  • 因此,您的计算机上有指向图书馆的路径语句,但这些语句不存在,因此您必须将它们带到 spec file

我建议在第一次尝试时进行一个目录安装而不是文件安装,这样会稍微容易一些。

好吧,我 运行 没有 -w 的 pyinstaller,所以命令提示符仍会打开。

我运行它得到了

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

因此,无论出于何种原因,即使将其制作成 exe,它仍然需要。所以新设备也需要它,奇怪但是很好。

现在这是一个新问题,所以我将从这里继续,但现在我知道了。 感谢所有阅读和评论的人!