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

fastStructure运行报错:Argument 'pi'类型不符(预期与实际均为allelefreq.AlleleFreq)

fastStructure运行时TypeError问题解决(Ubuntu 20.04.6)

问题描述

在Ubuntu 20.04.6系统完成fastStructure安装后,执行测试命令:

python structure.py -K 3 --input=test/testdata --output=test/testoutput_simple --full --seed=100

触发如下错误:

Traceback (most recent call last):
  File "/fastStructure/structure.py", line 176, in <module>
    Q, P, other = fastStructure.infer_variational_parameters(G, params['K'], \
  File "fastStructure.pyx", line 101, in fastStructure.infer_variational_parameters
    E = mlhood.marginal_likelihood(G, psi, pi)
TypeError: Argument 'pi' has incorrect type (expected allelefreq.AlleleFreq, got allelefreq.AlleleFreq)

导致testoutput_simple.3.log为空,其余输出文件缺失。

解决方法

1. 重新编译Cython模块

该错误多由Cython编译生成的模块与当前Python环境不兼容导致,重新编译可修复类型识别问题:

  • 进入fastStructure根目录
  • 清理旧编译文件:
    rm -rf *.c *.so build/
    
  • 使用当前Python环境重新编译:
    python setup.py build_ext --inplace
    
    注意:若系统存在多版本Python,需确保使用安装fastStructure时的对应环境。

2. 匹配依赖版本

fastStructure对numpy、cython版本有特定要求,版本不匹配会引发类型错误:

  • 检查当前依赖版本:
    python -c "import numpy; print(numpy.__version__)"
    python -c "import cython; print(cython.__version__)"
    
  • 安装兼容版本(推荐组合):
    pip uninstall numpy cython
    pip install numpy==1.21.6 cython==0.29.32
    
  • 重新编译fastStructure模块。

3. 切换至Python 3.7环境

Ubuntu 20.04默认Python 3.8与fastStructure存在兼容性问题,可通过虚拟环境使用Python 3.7:

  • 安装Python 3.7:
    sudo apt-get install python3.7 python3.7-dev python3.7-venv
    
  • 创建并激活虚拟环境:
    python3.7 -m venv faststruct_env
    source faststruct_env/bin/activate
    
  • 在虚拟环境内重新安装依赖并编译:
    pip install numpy==1.21.6 cython==0.29.32
    python setup.py build_ext --inplace
    
  • 在此环境中重新运行测试命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 05:44:58