Spyder: TabError: inconsistent use of tabs and spaces in indentation

Created on 1 Nov 2019  路  16Comments  路  Source: spyder-ide/spyder

Description

What steps will reproduce the problem?

I prefer Sypder over a larger IDE to have a lighter tool to try some code.
So I am copy-pasting a lot of code from external source, add something, ...
Too often I get the error message "TabError: inconsistent use of tabs and spaces in indentation", likely because some code uses spaces other tabs. Manual fixing this is quite cumbersome.
The function "fix identation" does help here either.

On top of that when I actually give up and replace tabs with spaces, delete the tab, insert spaces, the "tool tips" pop up for no reason ... and if I press the wrong button, I also suddenly have some code in there which I did not want.

Makes this version of Spyder almost unusable ....

Versions

  • Spyder version: 4.0.0b7
  • Python version: 3.8.0+
  • Qt version: 5.12.4
  • PyQt5 version: 5.12.3
  • Operating System: Linux 4.19.79-1-MANJARO

Dependencies

cloudpickle >=0.5.0          :  1.2.2 (OK)
pygments >=2.0               :  2.4.2 (OK)
qtconsole >=4.5.5            :  4.5.5 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
sphinx >=0.6.6               :  2.2.1 (OK)
pylint >=0.25                :  2.4.3 (OK)
psutil >=0.3                 :  5.6.3 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.5.0;<2.0.0:  1.6.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  None (NOK)
cython >=0.21                :  None (NOK)
IPython >=4.0                :  7.9.0 (OK)
matplotlib >=2.0.0           :  None (NOK)
pandas >=0.13.1              :  None (NOK)
numpy >=1.7                  :  None (NOK)
scipy >=0.17.0               :  None (NOK)
pyls >=0.28.2;<0.29.0        :  0.28.3 (OK)
xdg >=0.26                   :  0.26 (OK)
Editor Bug

Most helpful comment

this error is so annoying, im not sure why it happens, everytime it happens i have to fix it by opening the code in sublime text-->view-->identation-->convert identation to tabs

All 16 comments

The function "fix identation" does help here either.

I guess you mean here "does not help". But why not? What's the problem? Please be more specific.

On top of that when I actually give up and replace tabs with spaces, delete the tab, insert spaces, the "tool tips" pop up for no reason ... and if I press the wrong button, I also suddenly have some code in there which I did not want.

I don't understand very well what you mean here. Please create a simple video and post it here to clarify.

this error is so annoying, im not sure why it happens, everytime it happens i have to fix it by opening the code in sublime text-->view-->identation-->convert identation to tabs

this error is so annoying

But what is the error? Please post the error so we can understand how to fix it.

As I described in the initial post:
"So I am copy-pasting a lot of code from external source, add something, ..."
Likely there is some code with used tabs for indentation others spaces, so you end up with mixture of both and get said error message.
In the meantime I discovered the option to display spaces and tabs, so in that case you could spot the problem, but still you would need to (manually?) change every ident.

  • I haven't found a function in Spyder to change idents from/to spaces/tabs
  • The function "fix identation" does help not here either
  • not manually, not (semi)automatically
  • other IDEs (ie Pycharm) provide conversion options and silently, automatically any copy-pasted text to fit the current ident style so that such error never pops up

@SvenMeyer, please upload a file with mixed tabs and spaces for which "Fix indentation" is not working, to see if we can reproduce the error in our side.

@ccordoba12 fyi it is hard to provide an example here.
why? because by copying and pasting it here it can mix the hiden info that cause that error to happens

You can attach a file @isalirezag or provide us with an error traceback (or both :-) )

@isalirezag, you can upload a file directly here instead of pasting its contents.

@SvenMeyer, @isalirezag, we're still waiting for a file from you guys.

untitled0.py.zip

@ccordoba12 This should give you the error :)

Great, thanks!

@ccordoba12
This bug still exists in spyder 4.1.1
I'm using ubuntu 16.04
Python 3.6.6 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Linux 4.15.0-91-generic

just clear the indentation and then again give identation by tab. It works in my case in spyder4

@nishant2k how to clear the indentation? it does not work for me

Temporary solution is to change the indentation characters to 4 spaces in Tools>Preferences>Editor>Advanced settings.

same issue here: Ubuntu 18.04 Spyder 4.1.4 Python 3.8.3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spyder-bot picture spyder-bot  路  3Comments

LDONT picture LDONT  路  3Comments

hedeqing picture hedeqing  路  3Comments

gabrielclow picture gabrielclow  路  3Comments

ok97465 picture ok97465  路  3Comments