VS Code(Windows)下ModuleNotFoundError: No module named 'schedule'求助
问题描述
运行Python代码时出现以下错误:
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'
已尝试操作:
- 更换VS Code中的Python解释器
- 更新电脑上的Python版本
- 使用pip3安装及重新安装
scheduler
运行的代码如下:
import schedule import time def job(): print("I'm working...") schedule.every(10).seconds.do(job) while True: schedule.run_pending() time.sleep(1)
解决步骤
修正包名安装:你安装的是
scheduler,但代码依赖的是schedule包,打开终端执行正确的安装命令:pip install schedule如果系统中有多个Python版本,明确指定解释器对应的pip:
- 针对Python3:
pip3 install schedule - 针对当前VS Code选中的解释器,在VS Code终端中执行:
python -m pip install schedule(确保终端激活了对应的虚拟环境)
- 针对Python3:
确认VS Code解释器与安装环境一致:
- 在VS Code中按下
Ctrl+Shift+P,输入Python: Select Interpreter,选中你正在使用的Python解释器 - 打开终端,执行
Get-Command python(PowerShell环境),查看当前终端使用的Python路径,确认和VS Code选中的解释器路径一致 - 如果路径不一致,在VS Code终端中激活对应的虚拟环境(若使用了虚拟环境),再重新安装
schedule包
- 在VS Code中按下
清理错误安装包:如果之前错误安装了
scheduler,可以执行pip uninstall scheduler清理,避免环境混淆
内容的提问来源于stack exchange,提问作者Muhammad Taimoor
相关产品推荐
相关产品推荐

