Search code examples
spyderindentationmultiline

Spyder IDE problem: Every indented statement throws an indentation error


I'm getting the "IndentationError: expected an indented block" error in every indented statement, no matter how simple. I've really hit a wall, so any help would be much appreciated.

I've gone through many similar questions on SO and to the best of my ability have taken care that I have the correct indentation in my code (and that I'm not mixing tabs and spaces).

With each of the below statements, I get the same "expected an indented block" error behind the first line's colon. I use tabs in Spyder, but will use 4 spaces to indent here.

if 3 + 5 > 0:
    print("8")

Throws the error:

In [6] if 3 + 5 > 0:
File "C:\Users\..\AppData\Local\Temp\ipykernel_12028\2022076979.py", line 1
if 3 + 5 > 0:
             ^
IndentationError: expected an indented block

Same error for:

for i in range(1,11): 
    print(i)

And also for:

def iris_data(): 
    print("hello")

All three statements run as given in the PyCharm IDE (as well as IDLE), so this seems to be an issue with Spyder's settings (or maybe installation?).

I like using Spyder as an IDE, so I'm really hoping someone has any idea what is causing these errors. Thanks.


Solution

  • I was running only the line by putting the cursor in/on it and pressing F9.

    What I wanted to do was run the cell by pressing ctrl+ return, or alternatively, select the entire piece of code I want to run and press F9.

    It's such a stupid mistake that I couldn't find anything on Google or Stack Overflow.

    Hope this maybe helps out another absolute beginner.