scikit-rf导入报错:numpy与collections属性缺失问题求助
环境配置
- Pop!OS 22.04 系统
- 安装有 Anaconda
- 基于 Python 3.8.18 的基础环境运行 Spyder
- 调用其他环境的解释器,所有环境均已安装 spyder-kernels 2.4.4
导入 scikit-rf 报错情况
- Python 3.9.16 + numpy 1.26.4 + scikit-rf 0.18.1 环境:
执行import skrf as rf时触发报错:
AttributeError: module 'numpy' has no attribute 'complex'.
- Python 3.12.2 + numpy 1.26.4 + scikit-rf 0.18.1 环境:
执行相同导入命令时触发报错:
AttributeError: module 'collections' has no attribute 'Sequence'
问题原因及解决办法
原因
这两个报错都是 scikit-rf 0.18.1 的版本兼容性问题:
- numpy 1.20 及以上版本已弃用
numpy.complex属性,改用numpy.complex_,但 scikit-rf 0.18.1 仍在使用旧写法,导致在高版本 numpy 中报错。 - Python 3.10 及以上版本将
collections.Sequence迁移到了collections.abc.Sequence,scikit-rf 0.18.1 未适配该变更,因此在 Python 3.12 中触发报错。
解决办法
- 优先升级 scikit-rf 到最新稳定版本(推荐 0.25+),新版本已修复上述兼容性问题。
- 若无法升级 scikit-rf:
- 针对 Python 3.9 环境,将 numpy 降级到 1.19.x 版本;
- Python 3.12 与 scikit-rf 0.18.1 完全不兼容,需将 Python 降级到 3.9 及以下版本,或者必须升级 scikit-rf。
内容的提问来源于stack exchange,提问作者Erik Iverson
相关产品推荐
相关产品推荐

