0

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

guizmo
  • 5
  • 3
  • Hi, there will be a error popping up at the console that flashes, try to take a capture of it and include the error code here – Delrius Euphoria Oct 02 '20 at 18:35
  • There really seems to be no error, it just flashes, then disappears, no additional messages. – guizmo Oct 02 '20 at 18:36
  • Start the exe from a command prompt then see what it shows – DisappointedByUnaccountableMod Oct 02 '20 at 18:38
  • Thank you barry! C:\Users\User\PycharmProjects\youtubeconverter\dist\guizmoytc>guizmoytc.exe Traceback (most recent call last): File "guizmoytc.py", line 2, in ModuleNotFoundError: No module named 'pytube' [6576] Failed to execute script guizmoytc – guizmo Oct 02 '20 at 18:48

1 Answers1

0

The problem is that pytube was installed in your virtual env given by pycharm and not in global python version, so say this in the terminal:

pip install pytube 

*Actually pytube3

Then run the pyinstaller line of code in the terminal where you installed the library from, and it should fix the error.

guizmo
  • 5
  • 3
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
  • Yes indeed i had installed those modules on the pycharm venv and not on my computer (not on python?)Alright, I installed pytube and youtube-dl in same same location as my python is located. install was successful. I reran the pyinstaller from my pycharm files. I got the exe file. I tried opening it from the command, now i get this: C:\Users\User\PycharmProjects\youtubeconverter\dist>guizmoytc.exe C:\Users\User\PycharmProjects\youtubeconverter\dist> And 5 seconds later, ''fatal error failed to execute script guizmoytc'' – guizmo Oct 02 '20 at 19:21
  • Am i installing the modules at the right place? Do i have to install where my python is located or wherepycharm is located? – guizmo Oct 02 '20 at 19:22
  • Ok pardon actually i was using a different method, this is the error i get now when i used the same method as earlier: – guizmo Oct 02 '20 at 19:28
  • ```Traceback (most recent call last): File "guizmoytc.py", line 2, in File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module exec(bytecode, module.__dict__) File "pytube\__init__.py", line 16, in File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module exec(bytecode, module.__dict__)``` – guizmo Oct 02 '20 at 19:33
  • ```File "pytube\streams.py", line 17, in File "c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module exec(bytecode, module.__dict__) File "pytube\extract.py", line 7, in ImportError: cannot import name 'quote' from 'pytube.compat' (C:\Users\User\PycharmProjects\youtubeconverter\dist\guizmoytc\pytube\compat.pyc) [9596] Failed to execute script guizmoytc``` – guizmo Oct 02 '20 at 19:33
  • @guizmo Yes, to fix this say `pip install pytube3` and follow [this](https://stackoverflow.com/a/64091230/13382000) – Delrius Euphoria Oct 02 '20 at 19:54
  • @Cool_Cloud Working, thank you good sir. I have learned alot today – guizmo Oct 02 '20 at 20:07
  • @Cool_Cloud how do i even do that? I cannot upvote i am too new – guizmo Oct 02 '20 at 22:19
  • @guizmo - Please take a look [here](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – Delrius Euphoria Oct 02 '20 at 22:21