user29712751
user29712751

Reputation: 1

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

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.

Upvotes: 0

Views: 51

Answers (2)

dev_light
dev_light

Reputation: 4031

Information from the docs and PyPI shows that the latest version of pytube i.e. 15.0.0 supports Python 3.7 - 3.11. From your comments, you are using Python 3.13.

Downgrade to Python 3.11, and install this package in a dedicated virtual environment.

Upvotes: 0

w1redch4d
w1redch4d

Reputation: 16

try using a virtual environment :

python -m venv venv

source ./venv/bin/activate # Linux
.\venv\Scripts\activate # Windows

pip3 install pytube # Linux
pip install pytube # Windows

also there is another issue being discussed in the github repo , also i would recommend using yt-dlp as this is updated more often and the bug fixes are quicker

Upvotes: 0

Related Questions