I have written a youtube converter which is working fine when i am running it from pycharm. I tried several ways to use pyinstaller to create an exe file out of the .py file below.
From the cd, in the correct directory,
when i try pyinstaller --onefile -w filename.py
or pyinstaller --onefile filename.py
, when i try to open the executable file, I get fatal error could not run script.
when i try pyinstaller filename.py
or python -m PyInstaller filename.py
, and then try to open the executable file, the cmd flashes and then nothing.
From pycharm, when I run the program, tkinter opens and all the functionalities are good.
Here is my code
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()
Thanks