Home > OS >  ModuleNotFoundError: No module named 'schedule' on VS Code Windows
ModuleNotFoundError: No module named 'schedule' on VS Code Windows

Time:09-22

I am using Python on VS Code (Windows). I am encountering the following error:

Traceback (most recent call last):
  File "c:\Users\taimo\Documents\Visual Studio Code Workloads\Python VS Code\DateTimeModule.py", line 1, in <module>
    import schedule
ModuleNotFoundError: No module named 'schedule'

I have tried many things to fix this issue, which include changing the Python interpreter in VS Code, updating the Python version on my computer, installing "scheduler" using pip3, uninstalling and reinstalling scheduler using pip3, however even after all this the issue has not been fixed.

It is infuriating, because a few days ago, it was working just fine without any errors, and today it suddenly started throwing this error. I shall be very grateful to you if you can solve this problem for me.

Thanks in advance!

The code I am running is:

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).seconds.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)



CodePudding user response:

This kind of error is basically caused by the existence of multiple python versions on the machine.

Ctrl Shift P --> Python:Select Interpreter --> Choosing the correct interpreter resolves the error.

Your best bet is to use a virtual environment, which manages python versions and various packages nicely.

  1. Use the following command in the vscode terminal to create a virtual environment

    python -m venv .venv
    
  2. Select the interpreter in the virtual environment

    enter image description here

  3. Create a new terminal activation environment

    enter image description here

  4. Install schedule package in virtual environment

    enter image description here

CodePudding user response:

Make sure your python /site-packages folder is added to PATH. Also, it is recommended that you have a separate environment for you to install libraries specific for a project.

  • Related