【问题标题】:Pyinstaller exe failed to execute scriptPyinstaller exe 执行脚本失败
【发布时间】:2018-12-09 00:39:58
【问题描述】:

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

【问题讨论】:

    标签: python python-2.7 exe pyinstaller


    【解决方案1】:

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

    我运行它并得到了

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

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

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

    【讨论】:

    • 是的,Wand 要求安装 Imagemagick。所以这对我来说有点道理。传输所有 Python 组件不会安装非 Python Imagemagick。
    • @fmw42 因此,即使我已将它安装在制作 exe 的计算机上,它仍然需要它运行在任何其他计算机上吗?
    • 我认为这是正确的。但我不是 Python 专家,也不是使用 PyInstaller。我会听从其他 Python 和 Wand 专家的意见。
    • 该死,这简直令人心碎......哦,现在我知道了,谢谢!
    【解决方案2】:

    这些是您可能想到也可能没有想到的一般性问题:

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

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

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

    【讨论】:

    • 我想,因为我一直只是获取程序所在的当前路径,并且没有具体说我不需要规范文件?有没有办法解决 32 位和 64 位问题?
    • 我刚刚检查了另一台电脑确认,它是一个和我一样的64位平台,我也带了.spec文件,它没有工作。可悲的是,看起来这些不是手头的问题,但感谢您的回答,因为我学到了一些新东西! ^-^
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 2020-01-23
    • 2018-06-07
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多