Pyinstaller exe执行脚本失败

时间:2018-06-29 19:20:12

标签: python python-2.7 exe pyinstaller

这是我的代码,我可以在计算机上运行它。一旦我将其通过闪存驱动器移至另一台计算机并尝试将其打开,它就会读取无法执行脚本的信息。 我将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()

2 个答案:

答案 0 :(得分:0)

这些是您可能会或可能不会想到的一般事情:

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

  • 因此,您有一些指向计算机上库的路径语句,但这些语句不存在,那么您必须将它们带到spec file中。

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

答案 1 :(得分:0)

好吧,我在没有-w的情况下运行pyinstaller,因此命令提示符仍将打开。

我运行并得到

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

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

这是新问题,因此我将继续进行,但是现在我知道了。 感谢所有阅读和评论的人!