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

运行Python聊天程序时出现AttributeError: module 'time' has no attribute 'clock'错误

解决AttributeError: module 'time' has no attribute 'clock'问题

这个错误的核心原因是Python 3.8及以上版本移除了time.clock()方法,而你使用的SQLAlchemy版本过于老旧,代码中仍在调用这个已废弃的方法,导致兼容性冲突。

解决方案

  • 升级SQLAlchemy到兼容Python3.8+的版本,执行以下命令:
    pip install --upgrade sqlalchemy
    
  • 如果升级SQLAlchemy后ChatterBot出现其他兼容性问题,建议同步升级ChatterBot:
    pip install --upgrade chatterbot
    
  • 若不想升级依赖,可手动修改SQLAlchemy的兼容文件:找到报错路径C:\Users\atulk\anaconda3\lib\site-packages\sqlalchemy\util\compat.py,将第264行的time_func = time.clock替换为:
    time_func = time.perf_counter
    
    (time.perf_counter()是Python3.3+官方推荐的替代方法,功能与原time.clock()一致)

内容的提问来源于stack exchange,提问作者Atulk-14

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 16:15:39