【发布时间】:2020-10-02 18:30:40
【问题描述】:
我编写了一个 youtube 转换器,当我从 pycharm 运行它时它工作正常。我尝试了几种方法来使用 pyinstaller 从下面的 .py 文件中创建一个 exe 文件。
从 cd 中,在正确的目录中,
当我尝试pyinstaller --onefile -w filename.py 或pyinstaller --onefile filename.py 时,当我尝试打开可执行文件时,出现致命错误无法运行脚本。
当我尝试pyinstaller filename.py 或python -m PyInstaller filename.py,然后尝试打开可执行文件时,cmd 闪烁,然后什么也没有。
从pycharm,当我运行程序时,tkinter打开并且所有功能都很好。
这是我的代码
from tkinter import *
from pytube import YouTube
import youtube_dl
window = Tk()
window.title("Convertiseur Youtube 1.0")
window.configure(background="silver")
window.geometry("600x250")
def clickvideo():
url = textentry.get()
YouTube(url).streams.filter(file_extension='mp4').first().download()
textentry.delete(0, END)
status.set("Succès! Le fichier mp4 a été envoyé à l'endroit à partir du quel ce programme est exécuté.")
def clickaudio():
video_info = youtube_dl.YoutubeDL().extract_info(
url=textentry.get(), download=False
)
filename = f"{video_info['title']}.mp3"
options = {
'format': 'bestaudio/best',
'keepvideo': False,
'outtmpl': filename,
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}]
}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([video_info['webpage_url']])
textentry.delete(0, END)
status.set("Succès! Le fichier mp3 a été envoyé à l'endroit à partir du quel ce programme est exécuté.")
Label(window, background="silver").pack()
Label(window, text="Lien Youtube à convertir:", background="silver").pack()
Label(window, background="silver").pack()
textentry = Entry(window, width=60)
textentry.get()
textentry.pack()
Label(window, background="silver").pack()
videobutton = Button(window, text="Convertir en vidéo", width=16, command=clickvideo).pack()
Label(window, background="silver").pack()
audiobutton = Button(window, text="Convertir en audio", width=16, command=clickaudio).pack()
Label(window, background="silver").pack()
status = StringVar()
status.set("Si rien ne se passe, il y a un problème avec le lien (typo ou mauvais lien).")
status_label = Label(window, background="silver", textvariable=status)
status_label.pack()
window.mainloop()
谢谢
【问题讨论】:
-
您好,控制台会弹出一个闪烁的错误,尝试捕获它并在此处包含错误代码
-
真的好像没有报错,只是一闪一闪,然后又消失了,没有额外的信息。
-
从命令提示符启动 exe,然后查看它显示的内容
-
谢谢巴里! C:\Users\User\PycharmProjects\youtubeconverter\dist\guizmoytc>guizmoytc.exe Traceback(最近一次调用最后一次):文件“guizmoytc.py”,第 2 行,在
ModuleNotFoundError: No module named 'pytube' [6576 ] 执行脚本 guizmoytc 失败
标签: python tkinter pyinstaller executable