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

使用img2table提取考勤表图片表格时遇版本兼容错误求助

解决方案

1. 锁定兼容版本组合(最稳妥)

img2table 1.2.11的依赖对numpy和numba的版本有特定兼容范围,推荐使用经过验证的版本配对:

  • 卸载现有冲突包:
    pip uninstall -y numpy numba img2table
    
  • 安装指定版本:
    pip install numpy==1.23.5 numba==0.56.4 img2table==1.2.11
    

这个组合里numpy还保留np.long属性,同时numba支持numpy.average函数,能直接解决两个错误。

2. 适配新版本numpy(无需降级)

如果必须使用较新的numpy(>=1.24,该版本移除了np.long),可以在代码开头添加补丁,将np.long映射为等价的np.int64:

import numpy as np
# 修复np.long不存在的问题
if not hasattr(np, 'long'):
    np.long = np.int64

# 之后再导入img2table模块
from img2table.document import Image

同时确保numba版本在0.57.x及以上,该版本对新numpy的兼容性更好,能解决numpy.average的TypingError。

3. 修正自定义加权平均函数

如果坚持用手动实现的加权平均函数,要确保符合numba的JIT编译要求,避免使用numba不支持的语法或参数:

from numba import jit

@jit(nopython=True)
def weighted_average(arr, weights):
    total_weight = weights.sum()
    if total_weight == 0:
        return 0.0
    return (arr * weights).sum() / total_weight

这个函数仅使用numba支持的numpy操作,能绕过numpy.average的兼容问题。

内容的提问来源于stack exchange,提问作者Akeen Karkare

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 01:44:59