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

运行Biopython导入SeqIO代码时出现循环导入错误,求助解决

Biopython导入错误:无法导入'_pairwisealigner'

我运行这段简单的Biopython代码时:

from Bio import SeqIO
for seq_record in SeqIO.parse("ls_orchid.fasta", "fasta"):
    print(seq_record.id)
    print(repr(seq_record.seq))
    print(len(seq_record))

一直遇到如下错误:

ImportError: cannot import name 'pairwisealigner' from partially initialized module 'Bio.Align' (most likely due to a circular import) (C:\Users\conno\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\Bio\Align_init.py)

查看Bio/Align/__init__.py里的注释说明:

# Import errors may occur here if a compiled _pairwisealigner.c file or
# compiled _codonaligner.c file (_pairwisealigner.pyd or _pairwisealigner.so,
# or _codonaligner.pyd or _codonaligner.so) is missing or if the user is
# importing from within the Biopython source tree, see PR #2007:
# https://github.com/biopython/biopython/pull/2007

我完全搞不懂这些内容,不知道该怎么解决这个问题。


解决方案

  • 重新安装Biopython:错误核心是编译后的组件缺失,先卸载再重装能解决大部分问题:

    pip uninstall biopython -y
    pip install biopython
    

    注意:Python 3.12需要Biopython 1.81及以上版本支持,安装时会自动匹配适配版本。

  • 不要在Biopython源码目录运行脚本:如果你的脚本放在Biopython的源码文件夹里,会触发循环导入。把脚本移到其他目录再执行。

  • 手动补全编译文件:如果重装后还是不行,确认你的系统架构(x86/ARM)和Python版本一致,找到对应版本的_pairwisealigner.pyd(Windows)或_pairwisealigner.so(Linux/macOS),替换到Bio/Align目录下的同名文件。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 09:22:40