这是我的代码:
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
my_seq = Seq("GATCG", IUPAC.unambiguous_dna)
for index, letter in enumerate(my_seq):
print("%i %s" %(index, letter))
print (len(my_seq))
我收到错误“无法从Bio.Seq导入Seq”。
终端错误如下:
Traceback (most recent call last):
File "sequence-length.py", line 1, in <module>
from Bio.Seq import Seq
File "/home/tanuj/.local/lib/python2.7/site-packages/Bio/Seq.py", line 21, in <module>
import string # for maketrans only
File "/home/tanuj/Desktop/biopython/scripts-test/string.py", line 1, in <module>
from Bio.Seq import Seq
ImportError: cannot import name Seq
我不确定问题是什么,因为代码工作正常,但过了一段时间,解释器无法导入Seq并开始显示错误。我该如何解决这个问题?
答案 0 :(得分:0)
你的剧本:
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
my_seq = Seq("GATCG", IUPAC.unambiguous_dna)
print(len(my_seq))
for index, letter in enumerate(my_seq):
print(index, letter)
在Python 3中适合我:
% python3 test.py
5
0 G
1 A
2 T
3 C
4 G
阅读您的错误消息,我猜您的问题是您有一个名为string.py的个人代码文件(“/home/tanuj/Desktop/biopython/scripts-test/string.py”),这与Python混淆了库它要导入的string.py:
% touch string.py
% python3 test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
from Bio.Seq import Seq
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/Seq.py", line 25, in <module>
from Bio._py3k import range
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/_py3k/__init__.py", line 170, in <module>
from urllib.request import urlopen, Request, urlretrieve, urlparse, urlcleanup
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 88, in <module>
import http.client
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 71, in <module>
import email.parser
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/feedparser.py", line 27, in <module>
from email._policybase import compat32
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/_policybase.py", line 7, in <module>
from email import header
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/header.py", line 16, in <module>
import email.quoprimime
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/email/quoprimime.py", line 44, in <module>
from string import ascii_letters, digits, hexdigits
ImportError: cannot import name 'ascii_letters'
%
将您的个人string.py文件重命名为其他内容。