I am using Python on VS Code (Windows). I am encountering the following error:
Traceback (most recent call last):
File "c:UserstaimoDocumentsVisual Studio Code WorkloadsPython VS CodeDateTimeModule.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)
2
Answers
Make sure your python
/site-packages
folder is added toPATH
. Also, it is recommended that you have a separate environment for you to install libraries specific for a project.This kind of error is basically caused by the existence of multiple python versions on the machine.
Your best bet is to use a virtual environment, which manages python versions and various packages nicely.
Use the following command in the vscode terminal to create a virtual environment
Select the interpreter in the virtual environment
Create a new terminal activation environment
Install
schedule
package in virtual environment