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

Python3.8导入pyqtgraph遇AttributeError:time模块无clock属性

解决Python3.8中导入pyqtgraph时AttributeError: module 'time' has no attribute 'clock'的问题

这个问题的根源是你使用的pyqtgraph版本里,ptime.py模块仍在调用Python3.3起就已被弃用的time.clock()方法,而Python3.8彻底移除了该方法,进而触发报错。下面是直接有效的修复方案:

手动修改pyqtgraph源码解决

  1. 定位目标文件:根据你的错误栈,ptime.py的路径为C:\Users\mpnlo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyqtgraph\ptime.py
  2. 用文本编辑器打开该文件,找到第24行的代码:
    cstart = systime.clock() ### Required to start the clock in windows
    
  3. 将其替换为Python3.3+推荐的高分辨率计时方法:
    cstart = systime.perf_counter() ### Required to start the clock in windows
    
  4. 检查文件内其他time.clock()调用(比如可能存在的计时差值计算代码),统一替换为perf_counter():
    • 例如若有return systime.clock() - cstart这类代码,修改为return systime.perf_counter() - cstart即可

time.perf_counter()是专门用于短时间计时的高精度计时器,完全可以替代旧的time.clock(),而且在Windows和Linux系统下都能稳定工作,不需要额外的系统分支判断。

额外说明

如果你担心修改源码会影响后续版本更新,可以先执行pip install --upgrade pyqtgraph再次确认是否安装了最新版pyqtgraph,但从你的描述来看,当前最新版可能还未修复这个兼容性问题,所以手动修改是最直接的解决方式。

内容的提问来源于stack exchange,提问作者Micheal Nestor

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 08:17:41