Python Pyinstaller+;司机

Python Pyinstaller+;司机,python,python-2.7,python-3.x,pyinstaller,youtube-dl,Python,Python 2.7,Python 3.x,Pyinstaller,Youtube Dl,我做这个脚本是为了从youtube上下载音乐,它在我空闲的时候可以工作,编译后在.exe中仍然可以工作 from tkinter import * from tkinter import ttk from tkinter import messagebox from tkinter import filedialog import youtube_dl import os class f(object): def __init__(self, finestra):

我做这个脚本是为了从youtube上下载音乐,它在我空闲的时候可以工作,编译后在.exe中仍然可以工作

from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from tkinter import filedialog
import youtube_dl
import os



class f(object):
    def __init__(self, finestra):
        self.finestra = finestra
        self.top = ttk.Frame(self.finestra, padding="10 10 10 10")
        self.top.grid(column=5, row=5)
        self.top.columnconfigure(1, weight=1)
        self.top.rowconfigure(1, weight=1)

        self.finestra.bind("<Return>",self.esegui_query)

        self.link = StringVar()
        self.esito = StringVar()
        self.bitrate = StringVar()
        self.esito.set("In Attesa")

#RIGA 1
        ttk.Label(self.top, text="Link:").grid(column=0,row=0)
        ttk.Entry(self.top, textvariable=self.link).grid(column=1,row=0)
        ttk.Button(self.top, text="Scarica", command=self.esegui_query).grid(column=2,row=0)
#RIGA 2
        ttk.Label(self.top, text="Bitrate:").grid(column=0,row=1)
        r1 = Radiobutton(self.top, text="192", variable=self.bitrate, value="192", cursor="dot")
        r1.grid(column=1,row=1)
        r2 = Radiobutton(self.top, text="320", variable=self.bitrate, value="320", cursor="dot")
        r2.grid(column=2,row=1)
        r1.select()
        ttk.Label(self.top, textvariable=self.esito).grid(column=3,row=1)

    def esegui_query(self,*argv):
        link = self.link.get()
        bitrate=self.bitrate.get()
        ydl_opts = {
        #'format': 'bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': bitrate,
                        }],
                    }
        self.esito.set("Downloading...")
        try:
            with youtube_dl.YoutubeDL(ydl_opts) as ydl:
                ydl.download([link])
            self.esito.set("Encoding...")
            for file in (os.listdir('.')):
                if file.endswith('.mp3') or file.endswith('.m4a') or file.endswith('.mp4'):
                    file2 = file[::-1][16:][::-1]
                    break
            self.esito.set("Download Completato")
        except Exception as e:
            self.esito.set("ERRORE")
            messagebox.showwarning("ERRORE",e)



finestra = Tk()
finestra.title("Download Youtube")
f = f(finestra)
finestra.mainloop()
导游怎么说


如何在使用pyinstaller编译脚本时包含这些驱动程序,以使脚本在其他pc中工作

您可以编辑.spec文件以包含驱动程序作为额外数据:

a = Analysis(...
 datas=[ ('folder\your_driver', '.') ],
 ...
 )

现在,当您使用pyinstaller编译时,驱动程序将被复制。问题在于,驱动程序的位置必须与.exe位于同一位置,这样它才能在任何用户的系统上找到它

也可以使用命令行参数:

--resource RESOURCE
--resource RESOURCE