0

This is my code:

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))

I get an error "Unable to import Seq from Bio.Seq".

Error on terminal is given below:

 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

I am not sure what the problem is, because the code was working fine, but after some time, the interpreter was unable to import Seq and started showing the error. How can I fix this?

2
  • 1
    I'll give you a couple of tips before your question gets downvoted. First fix the formatting, your error is unreadable. Second, take your time to elaborate a question and describe it the best possible way, as I don't understand what your problem is and others won't either. Third, explain what have you tried when it was working, and what changed now that it's not working. Cheers ~ Commented May 9, 2018 at 16:07
  • 1
    Don't pick module names the standard library has dibs on. Commented May 9, 2018 at 19:09

1 Answer 1

0

Your script:

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)

works fine for me in Python 3:

% python3 test.py
5
0 G
1 A
2 T
3 C
4 G

Reading your error messages, my guess your problem is you have a personal code file named string.py ("/home/tanuj/Desktop/biopython/scripts-test/string.py") which Python is confusing with the library string.py it wants to import:

% 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'
% 

Rename your personal string.py file to something else.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.