[Python] Trying to run my file in windows command prompt but can't find pytube

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to make a python file that converts the argument (a youtube link) provided in command prompt something like C:\Users\Username\Desktop>YTMP3.py URL however, the script can't find the third party library named pytube, the resulting error is ModuleNotFoundError: No module named 'pytube'

    Code:

    import pytube
    import os
    import sys
    from pathlib import Path
    from pytube import YouTube

    destination = 'C:/Desktop/' + str(Path.home()) + '/Downloads'

    def download_audio(url):
    yt = YouTube(url)
    print("Title: ", yt.title)
    base, ext = os.path.splitext(yt)
    newfile = base + ".mp3"
    print("Downloading...")
    yt.streams.filter(only_audio=True).first().download(output_path=destination, filename=newfile)
    print("Download complete")

    if __name__ == "__main__":
    download_audio(str(sys.argv[1]))


    I made sure the module was installed, I was expecting the module to run normally and download the YouTube URL I provided.

    Continue reading...

Compartilhe esta Página