What is the “inconsistent use of tabs and spaces in indentation” error and why is it caused? and what is the solution

Reading Time: 2 minutes

Knowingly or unknowingly you have used spaces instead of tabs, or the tabs are inconsistent in your python code. To solve this problem you should first make it apparent what is culprit and where is the culprit. I mean to display the spaces and Tabs. To see that you can follow the steps below in the editor that you are using.

Sublime Text 3

Make all whitespace characters visible, in Sublime text you should edit Preferences > Settings > User Settings

In your User Settings file add this config. Also if this is the last line in the config don’t end with a comma.

    "draw_white_space": "all"

After applying the settings you can easily see it as shown below.

inconsistent use of tabs and spaces in indentation

…… – > Denotes the spaces

——- -> Denote the tabs

Also, make sure in Sublimetext 3 menu: Views -> Indentation > Indent using Spaces ( is checked, has tick mark )

VS Code 1.6.0 and Greater

editor.renderWhitespace is now an enum taking either noneboundary or all. To view all whitespaces:

"editor.renderWhitespace": "all", 

Before VS Code 1.6.0

Before 1.6.0, you had to set editor.renderWhitespace to true:

"editor.renderWhitespace": true

Vim editor

You can open the file and give ESC : set list

Except spaces, every other whitespace characters will be clearly visible as shown below.

Steps to Fix these kinds of errors

  1. Don’t use tabs and spaces mixed.
  2. Always use spaces as tabs. In sublime text 3 you can enable this by View > Indentation > Indent using Space.