34

I am very new to Python and I am used to R studio so I choose Spyder. On the Spyder layout I saw a button 'run current line (ctrl +f10)'. But it doesn't work by pressing the button or c+10. Am I missing something? I can only select the script and 'ctrl+enter ' to run current line which is not convenient at all. I am using ubuntu with Anaconda distribution.

Jim
  • 385
  • 1
  • 3
  • 7

5 Answers5

62

The key to run the current line by itself is F9. The shortcut ctrl+F10 is used if you are in debugging mode.

You can see a list of shortcuts by selecting Preferences in the Tool menu, and then clicking on Keyboard shortcuts.

Jitse Niesen
  • 4,492
  • 26
  • 23
  • In Spyder 3.3.6, on 2 different machines running _Windows 10_, _F9_ does not work for me but selecting the menu option _Run selection or current line_ does. Also, selecting the text and clicking _Ctrl+Return_ does work however! – boardtc Nov 07 '19 at 00:51
25

Coming from R studio I imagine you were hoping to have a command that runs the next command, rather than just that one row (which can break a command into several parts and cause errors).

The exact equivalent doesn't exist yet but if you get accustomed to adding #%% before and after chunks ("cells") you want to run together then you can use the following commands to run the whole chunk.

Run cell: Ctrl + Return
Run cell and advance : Shift+Return

Kirk Geier
  • 499
  • 8
  • 15
  • 3
    This answer was very useful as it gave context information from some coming from RStudio using Rnotebooks to Spyder for similar functionality. – ansek Jun 14 '19 at 00:49
6

F9 is the key that does the job for you. To replicate the RStudio style, go to Preferences in Tools menu and go to Keyboard Shortcuts.

Since Ctrl + Enter is assigned to another function, change that first. Then assign the F9 key value to Ctrl + Enter. Now Spyder is the same as RStudio. Atleast in a way.

Praveen Kumar
  • 321
  • 3
  • 5
1

Some keyboards have a different layout than others in terms of what the keys are supposed to do. For me running happens if done via Fn + F9.

Momchill
  • 417
  • 6
  • 15
-1

Control Enter is a quick way of executing a line or block of code in both R Studio & Python.

In Spyder, make sure the line or block is highlighted before you hit 'ctrl-enter'

zach
  • 759
  • 1
  • 9
  • 21