You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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(确保终端激活了对应的虚拟环境)
  • 确认VS Code解释器与安装环境一致:

    1. 在VS Code中按下Ctrl+Shift+P,输入Python: Select Interpreter,选中你正在使用的Python解释器
    2. 打开终端,执行Get-Command python(PowerShell环境),查看当前终端使用的Python路径,确认和VS Code选中的解释器路径一致
    3. 如果路径不一致,在VS Code终端中激活对应的虚拟环境(若使用了虚拟环境),再重新安装schedule包
  • 清理错误安装包:如果之前错误安装了scheduler,可以执行pip uninstall scheduler清理,避免环境混淆

内容的提问来源于stack exchange,提问作者Muhammad Taimoor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 11:30:49