Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm TabError: inconsistent use of tabs and spaces in indentation

Tags:

python

pycharm

In Pycharm I keep running into this error:

TabError: inconsistent use of tabs and spaces in indentation

I know its a problem with tabs/spaces.

I want:

if len(myresults)==0:
    print("TEST")

Whenever I type, pressing enter after every line typed I actually type:

if len(myresults)==0:
        print("TEST")

Causing this error. How do I fix it? Here are my setting s for pycharm:

Pycharm Settings

I'm probably missing something obvious, but I simply cannot find it.

like image 850
Dillsac Avatar asked Nov 12 '18 14:11

Dillsac


3 Answers

Try,

  1. In the "Settings | Editor | Code Style" -- try disabling "Detect and use existing file indents for editing" in case if you have it enabled (it is by default). NOTE: re-opening file in editor may be required.
  2. Do you have any .editorconfig files anywhere in the path of that file? Settings from .editorconfig have priority (will overwrite) over your IDE settings.
like image 112
Nipun Sampath Avatar answered Sep 28 '22 09:09

Nipun Sampath


Go to Settings --> Editor --> Code Style --> Python --> Tabs and Idents.

Here activate (checkbox) Use tab character AND Smart tabs

Thats works for me.

like image 28
Manute Avatar answered Sep 28 '22 10:09

Manute


I'm using Pycharm and Jupyter Notebook and had the same problem with both of them. I could not fix it with "convert Indents", So I uninstalled some of the modules that I was using in my programm and reinstall them and worked for me.

like image 44
Hamideh Avatar answered Sep 28 '22 08:09

Hamideh