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

无法通过pip构建pandas_ods_reader的技术求助

解决pandas_ods_reader在Debian Sid+Python3.13下的构建失败问题

问题背景

升级Debian Sid系统后,在虚拟环境中重新构建Python依赖时,原本正常工作的pandas_ods_reader无法完成安装,核心原因是pip在构建依赖的旧版pandas(1.5.3)时编译失败,报错指向khash_python.h中复数类型的结构体访问错误。

核心报错信息

In file included from pandas/_libs/algos.c:809:
pandas/_libs/src/klib/khash_python.h: In function ‘kh_complex128_hash_func’:
pandas/_libs/src/klib/khash_python.h:140:36: error: request for member ‘real’ in something not a structure or union
  140 |     return kh_float64_hash_func(val.real)^kh_float64_hash_func(val.imag);
      |                                    ^
pandas/_libs/src/klib/khash_python.h:140:67: error: request for member ‘imag’ in something not a structure or union
...
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
ERROR: Failed building wheel for pandas
Failed to build lxml pandas

当前环境参数

  • 系统:Debian Sid
  • Python版本:3.13.3
  • GCC版本:14.2.0
  • pip版本:25.1
  • 已安装核心依赖:numpy 2.2.5、pandas 2.2.3

解决方案

1. 升级并复用现有依赖安装pandas_ods_reader

直接安装最新版pandas_ods_reader,并禁用构建隔离以复用当前环境已安装的兼容Python3.13的pandas版本:

pip install --upgrade pandas_ods_reader --no-build-isolation

--no-build-isolation参数会跳过临时构建环境,避免pip拉取不支持Python3.13的旧版pandas重新编译。

2. 手动指定兼容的pandas版本

如果上述命令仍失败,强制指定安装依赖支持Python3.13的pandas版本(2.1及以上):

pip install pandas>=2.1 pandas_ods_reader

3. 替代方案:直接基于odfpy实现ODS读取

若pandas_ods_reader仍无法安装,可直接使用其底层依赖的odfpy包实现read_ods功能,示例代码:

import pandas as pd
from odf.opendocument import load
from odf.table import Table, TableRow, TableCell

def read_ods(file_path, sheet_name=0):
    doc = load(file_path)
    tables = doc.getElementsByType(Table)
    
    # 定位目标工作表
    if isinstance(sheet_name, int):
        table = tables[sheet_name]
    else:
        table = next(t for t in tables if t.getAttribute('name') == sheet_name)
    
    # 提取单元格数据
    rows = []
    for row in table.getElementsByType(TableRow):
        cells = []
        for cell in row.getElementsByType(TableCell):
            text = ''.join(node.data for node in cell.childNodes if node.nodeType == node.TEXT_NODE)
            cells.append(text)
        rows.append(cells)
    
    # 转换为DataFrame,第一行作为表头
    return pd.DataFrame(rows[1:], columns=rows[0])

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 06:38:10