[Python] Why does my computer keep saying that I successfully installed these libraries but...

Discussão em 'Python' iniciado por Stack, Maio 12, 2025.

  1. Stack

    Stack Membro Participativo

    Issue: ModuleNotFoundError for VLC and Pytube in Python Script


    I’m trying to run a Python script for a video player, but I keep encountering the following errors:

    ModuleNotFoundError: No module named 'vlc'
    ModuleNotFoundError: No module named 'pytube'


    Even though I have installed both modules using pip, they are not recognized in my script.

    Steps I’ve Taken to Resolve the Issue


    1. Tried Installing Modules

    I ran the following in the terminal inside VS Code:

    pip install python-vlc pytube

    The output confirmed successful installation:

    Successfully installed python-vlc-3.0.21203 pytube-15.0.0

    However, my script still does not recognize them.

    2. Checked Installed Packages I ran:

    pip list | grep -E "vlc|pytube"

    Both python-vlc and pytube appeared in the list.

    3. Tried Switching Python Environments


    • I checked my Python version using python --version.


    • I selected a different Python interpreter in VS Code via Ctrl + Shift + P > Python: Select Interpreter.

    I tried running the script in different environments, but the issue remained.

    4. Confirmed Installation Paths I ran:

    pip show python-vlc pytube

    This showed the installation path for both libraries, but they are still not recognized in my code. Here is what is showed:

    **Name: python-vlc Version: 3.0.21203 Summary: VLC bindings for python. Home-page: https://wiki.videolan.org/PythonBinding Author: Author-email: Olivier Aubert contact@olivieraubert.net License: LGPL-2.1+ Location: C:\Users\wsafe\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages Requires: Required-by:


    Name: pytube Version: 15.0.0 Summary: Python 3 library for downloading YouTube Videos. Home-page: https://github.com/pytube/pytube Author: Ronnie Ghose, Taylor Fox Dahlin, Nick Ficano Author-email: hey@pytube.io License: The Unlicense (Unlicense) Location: C:\Users\wsafe\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages
    Requires: Required-by:**

    I am not using a virtual environment and the issue persists across different Python versions and environments in VS Code.

    import os
    import time
    import vlc
    from pytube import YouTube

    # Get user input
    video_url = input("Enter the YouTube video URL: ")
    start_minutes = int(input("Enter start minutes (e.g., 1 for 1:30): "))
    start_seconds = int(input("Enter start seconds (e.g., 30 for 1:30): "))
    end_minutes = int(input("Enter end minutes: "))
    end_seconds = int(input("Enter end seconds: "))
    loop = input("Do you want to loop the video? (yes/no): ").strip().lower()
    loop_count = int(input("How many times should it loop? ") if loop == "yes" else 1)

    # Convert minutes & seconds into total seconds
    start_time = start_minutes * 60 + start_seconds
    end_time = end_minutes * 60 + end_seconds

    # Download video using pytube
    yt = YouTube(video_url)
    stream = yt.streams.filter(progressive=True, file_extension="mp4").order_by("resolution").desc().first()
    video_path = stream.download(output_path=os.getcwd())

    # Start VLC instance
    instance = vlc.Instance()
    player = instance.media_player_new()
    media = instance.media_new(video_path)
    media.add_option(f"start-time={start_time}") # Set start time
    player.set_media(media)

    # Loop video playback
    for _ in range(loop_count):
    print(f"Playing video from {start_minutes}:{start_seconds:02} to {end_minutes}:{end_seconds:02}...")
    player.play()

    time.sleep(end_time - start_time) # Wait until end time
    player.stop() # Stop playback
    time.sleep(1) # Short pause before replaying

    print("Playback finished.")


    Question


    How can I resolve the ModuleNotFoundError for vlc and pytube despite successful installation? Are there specific steps to ensure they are correctly recognized by my Python environment in VS Code?

    Continue reading...

Compartilhe esta Página