Question: Biopython Indentation Error
gravatar for priyasshah
7.0 years ago by
United States
priyasshah0 wrote:


I've been dabbling in biopython for about a year and I recently upgraded to Biopython release 1.59. I've been refreshing my skills with some tutorials (taken verbatim from the Biopython Cookbook) but I always get the error below when I run a for loop and any module from the biopython library:

IndentationError: expected an indented block

I only get this error when I call the .py file that I wrote in Komodo Edit version 7.0.2 from the command line terminal:

Priyas-iMac:~ Priya$ python /Users/priya/Documents/Python/Tutorials/
Traceback (most recent call last):
  File "/Users/priya/Documents/Python/Tutorials/", line 4, in <module>
    SeqIO.write(rc, "/Users/priya/Documents/Python/Tutorials/ls_orchid_rc.fasta", "fasta")
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/SeqIO/", line 400, in write
    from Bio import AlignIO
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/AlignIO/", line 147, in <module>
    import NexusIO
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/AlignIO/", line 19, in <module>
    from Bio.Nexus import Nexus
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/Nexus/", line 15, in <module>
    import os,sys, math, random, copy
  File "/Users/Priya/Documents/Python/Tutorials/", line 27
IndentationError: expected an indented block

But when I start up python directly and type in the tutorial example line by line it works fine:

Priyas-iMac:~ Priya$ python 
Python 2.7.3 (default, Apr 19 2012, 00:55:09) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from Bio import SeqIO
>>> for seq_record in SeqIO.parse("/Users/priya/Documents/Python/Tutorials/ls_orchid.txt","fasta"):
...      print

I can also still run old code that I wrote a year ago that has for loops and calls biopython modules, just not anything new that I write.

Any insight into this problem would be greatly appreciated!


biopython error • 2.0k views
ADD COMMENTlink modified 4.6 years ago by Biostar ♦♦ 20 • written 7.0 years ago by priyasshah0

Make sure that your indentation is consistent. In most editors there is an option to change space-tabs into tabs or tabs into space tabs. Try doing that for If that doesn't work, post the code as bow suggested.

ADD REPLYlink written 7.0 years ago by Niek De Klein2.5k

What version of Python are you using with your BioPython upgrade? Make sure they're compatible. I had some issues with indentation errors with the new Biopython 1.64 and Python 2.6.6, where the new biopython would work perfectly with 2.7.

ADD REPLYlink written 4.6 years ago by
gravatar for bow
7.0 years ago by
bow780 wrote:

Hi priyasshah,

It looks like there's an error in this file: "/Users/Priya/Documents/Python/Tutorials/". Could you paste the contents here:

ADD COMMENTlink written 7.0 years ago by bow780
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 687 users visited in the last hour