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,需确保使用安装fastStructure时的对应环境。python setup.py build_ext --inplace
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
相关产品推荐
相关产品推荐

