AttributeError: module 'Bio.SeqIO' has no attribute 'parse'
AttributeError: module 'Bio.SeqIO' has no attribute 'parse'
导入 Biopython 和解析文件的代码在我的笔记本电脑上运行。现在我有一个非常大的文件,我只能在另一台也安装了 python 和 Biopython 的计算机上解析它。但是在那台电脑上,它给了我错误信息。我已经卸载并重新安装了最新的 python 和 biopython。问题仍然存在。
整个代码为:
from Bio import SeqIO
with open('/Users/yuewang/work/18s_tree/aligned_fungi_rna.fasta', 'w') as output:
output.write('')
with open('/Users/yuewang/work/18s_tree/SILVA_132_SSURef_tax_silva_full_align_trunc.fasta') as fastafile:
record_iterator = SeqIO.parse(fastafile, 'fasta')
fungi = 'Eukaryota;Opisthokonta;Nucletmycea;Fungi;'
for record in record_iterator:
if fungi in record.id:
with open('/Users/yuewang/work/18s_tree/aligned_fungi_rna.fasta', 'a') as output:
output.write(record.format('fasta'))
错误信息:
Traceback (most recent call last):
File "copy.py", line 1, in <module>
from Bio import SeqIO
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Bio/SeqIO/__init__.py", line 391, in <module>
from . import UniprotIO
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Bio/SeqIO/UniprotIO.py", line 34, in <module>
from xml.etree import cElementTree as ElementTree
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/cElementTree.py", line 3, in <module>
from xml.etree.ElementTree import *
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/ElementTree.py", line 1660, in <module>
from _elementtree import *
File "/Users/yuewang/work/18s_tree/copy.py", line 7, in <module>
record_iterator = SeqIO.parse(fastafile, 'fasta')
AttributeError: module 'Bio.SeqIO' has no attribute 'parse'
如果我的问题不够清楚,请告诉我。
您的脚本被命名为 copy.py
,这将替换标准库 python copy
模块,从而提供非直观的 AttributeError
。将您的脚本重命名为其他名称,例如 my_copy.py
,它将起作用。
此代码片段演示了导入 SeqIO
会导入 copy
:
>>> import sys
>>> sys.modules['copy']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'copy'
>>> from Bio import SeqIO
>>> sys.modules['copy']
<module 'copy' from '/usr/lib64/python3.6/copy.py'>
导入 Biopython 和解析文件的代码在我的笔记本电脑上运行。现在我有一个非常大的文件,我只能在另一台也安装了 python 和 Biopython 的计算机上解析它。但是在那台电脑上,它给了我错误信息。我已经卸载并重新安装了最新的 python 和 biopython。问题仍然存在。
整个代码为:
from Bio import SeqIO
with open('/Users/yuewang/work/18s_tree/aligned_fungi_rna.fasta', 'w') as output:
output.write('')
with open('/Users/yuewang/work/18s_tree/SILVA_132_SSURef_tax_silva_full_align_trunc.fasta') as fastafile:
record_iterator = SeqIO.parse(fastafile, 'fasta')
fungi = 'Eukaryota;Opisthokonta;Nucletmycea;Fungi;'
for record in record_iterator:
if fungi in record.id:
with open('/Users/yuewang/work/18s_tree/aligned_fungi_rna.fasta', 'a') as output:
output.write(record.format('fasta'))
错误信息:
Traceback (most recent call last):
File "copy.py", line 1, in <module>
from Bio import SeqIO
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Bio/SeqIO/__init__.py", line 391, in <module>
from . import UniprotIO
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Bio/SeqIO/UniprotIO.py", line 34, in <module>
from xml.etree import cElementTree as ElementTree
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/cElementTree.py", line 3, in <module>
from xml.etree.ElementTree import *
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/xml/etree/ElementTree.py", line 1660, in <module>
from _elementtree import *
File "/Users/yuewang/work/18s_tree/copy.py", line 7, in <module>
record_iterator = SeqIO.parse(fastafile, 'fasta')
AttributeError: module 'Bio.SeqIO' has no attribute 'parse'
如果我的问题不够清楚,请告诉我。
您的脚本被命名为 copy.py
,这将替换标准库 python copy
模块,从而提供非直观的 AttributeError
。将您的脚本重命名为其他名称,例如 my_copy.py
,它将起作用。
此代码片段演示了导入 SeqIO
会导入 copy
:
>>> import sys
>>> sys.modules['copy']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'copy'
>>> from Bio import SeqIO
>>> sys.modules['copy']
<module 'copy' from '/usr/lib64/python3.6/copy.py'>