运行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_countertime.perf_counter()是Python3.3+官方推荐的替代方法,功能与原time.clock()一致)
内容的提问来源于stack exchange,提问作者Atulk-14
相关产品推荐
相关产品推荐

