117

In the main shell of IDLE, errors always return a line number but the development environment doesn't even have line numbers. Is there anyway to turn on line numbers?

GEOCHET
  • 20,623
  • 15
  • 71
  • 98
User
  • 20,562
  • 35
  • 99
  • 185
  • 4
    Wow, an IDE without line numbers? Does anyone else find that as bizarre as me? – Paul Feakins Mar 23 '19 at 12:54
  • 2
    @PaulFeakins The original IDLE designers apparently felt that the line number on the status bar and two ways to go to a line number were minimally sufficient. And there were technical issues in getting them right. I have used IDLE daily and for my use have hardly missed them. In any case, we just added them. Details in my answer. – Terry Jan Reedy Jul 25 '19 at 05:12
  • 1
    In Python 3.8 IDLE a new option has been added in the menu bar: Options -> Show Line Numbers – Diroallu Oct 27 '19 at 05:40

7 Answers7

158

Version 3.8 or newer:

To show line numbers in the current window, go to Options and click Show Line Numbers.

To show them automatically, go to Options > Configure IDLE > General and check the Show line numbers in new windows box.

Version 3.7 or older:

Unfortunately there is not an option to display line numbers in IDLE although there is an enhancement request open for this.

However, there are a couple of ways to work around this:

  1. Under the edit menu there is a go to line option (there is a default shortcut of Alt+G for this).

  2. There is a display at the bottom right which tells you your current line number / position on the line:

enter image description here

Community
  • 1
  • 1
ChrisProsser
  • 11,110
  • 6
  • 32
  • 42
  • 4
    On Mac the shortcut for navigating between lines is cmd+j. – tommy.carstensen Apr 25 '14 at 11:01
  • 6
    While this workaround works, why were numbered lines not included in the first release. It seems like an obvious feature. Very disappointing that this isn't included. – JayRugMan Dec 28 '17 at 01:29
  • If using brackets for scoping is confusing, then line numbers is rocket science. – aj.toulan May 30 '18 at 17:33
  • 2
    An enhanced patch for the line number request, issue 17535, was just merged. See my answer for details. – Terry Jan Reedy Jul 25 '19 at 05:08
  • not working, and this should be enabled by default, how do you find the source of the error while the reported error clearly states the line number, this makes no sens – user7082181 Mar 05 '21 at 19:22
15

There's a set of useful extensions to IDLE called IDLEX that works with MacOS and Windows http://idlex.sourceforge.net/

It includes line numbering and I find it quite handy & free.

Otherwise there are a bunch of other IDEs some of which are free: https://wiki.python.org/moin/IntegratedDevelopmentEnvironments

Davos
  • 3,886
  • 35
  • 55
  • 2
    Believe it or not, I really like Microsoft's VS Code now. It's a great light weight IDE with really good python plugins. It also works across mac/linux/windows. What a strange (good) world we live in where Microsoft is going open source. – Davos Jan 01 '17 at 21:31
7

If you are trying to track down which line caused an error, if you right-click in the Python shell where the line error is displayed it will come up with a "Go to file/line" which takes you directly to the line in question.

Martin Ghecea
  • 71
  • 1
  • 2
2

As it was mentioned by Davos you can use the IDLEX

It happens that I'm using Linux version and from all extensions I needed only LineNumbers. So I've downloaded IDLEX archive, took LineNumbers.py from it, copied it to Python's lib folder ( in my case its /usr/lib/python3.5/idlelib ) and added following lines to configuration file in my home folder which is ~/.idlerc/config-extensions.cfg:

[LineNumbers]
enable = 1
enable_shell = 0
visible = True

[LineNumbers_cfgBindings]
linenumbers-show = 
StahlRat
  • 709
  • 8
  • 21
  • Nice hacking! Seems like IDLE could do something similar to incorporate the code and settings to its internal cfg (as opposed to the extensions cfg) and wire up the option to the GUI. They probably didn't bother because IDLEX provides the functionality via plugin mechanism. – Davos Apr 18 '18 at 01:14
2

Line numbers were added to the IDLE editor two days ago and will appear in the upcoming 3.8.0a3 and later 3.7.5. For new windows, they are off by default, but this can be reversed on the Setting dialog, General tab, Editor section. For existing windows, there is a new Show (Hide) Line Numbers entry on the Options menu. There is currently no hotkey. One can select a line or bloc of lines by clicking on a line or clicking and dragging.

Some people may have missed Edit / Go to Line. The right-click context menu Goto File/Line works on grep (Find in Files) output as well as on trackbacks.

Terry Jan Reedy
  • 15,989
  • 1
  • 33
  • 48
0

As @StahlRat already answered. I would like to add another method for it. There is extension pack for Python Default idle editor Python Extensions Package.

0

As mentioned above (a quick way to do this) :

pip install IDLEX

Then I create a shortcut on Desktop (Win10) like this:

C:\Python\Python37\pythonw.exe "C:\Python\Python37\Scripts\idlex.pyw"

The paths may be different and need to be changed:

C:\Python\Python37

(Thanks for the great answers above)

Aaron
  • 138
  • 1
  • 9
  • Is `C:\Python\Python37\pythonw.exe "C:\Python\Python37\Scripts\idlex.pyw"` saved as .bat on Windows? – Ynjxsjmh Aug 29 '19 at 05:00
  • First, create Shortcut of pythonw.exe on desktop. Second, right click the shortcut -> property or attribute (R). Third, fill Target(T): with ```C:\Python\Python37\pythonw.exe "C:\Python\Python37\Scripts\idlex.pyw"```. done. – Aaron Aug 29 '19 at 11:25
  • Thanks, but I found we can create a `idlex.bat` file like what `Python36\Lib\idlelib\idle.bat` does and create shortcut for `idlex.bat`. – Ynjxsjmh Aug 29 '19 at 11:44