How to turn on line numbers in IDLE?
Asked Answered
F

7

120

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?

Fleurdelis answered 14/9, 2013 at 18:45 Comment(3)
Wow, an IDE without line numbers? Does anyone else find that as bizarre as me?Fantasist
@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.Batten
In Python 3.8 IDLE a new option has been added in the menu bar: Options -> Show Line NumbersValvate
S
165

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

Streetlight answered 14/9, 2013 at 19:2 Comment(5)
On Mac the shortcut for navigating between lines is cmd+j.Marden
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.Sacramentarian
If using brackets for scoping is confusing, then line numbers is rocket science.Repression
An enhanced patch for the line number request, issue 17535, was just merged. See my answer for details.Batten
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 sensIngeborgingelbert
A
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

Antinucleon answered 28/4, 2014 at 7:55 Comment(1)
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.Antinucleon
D
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.

Dysplasia answered 20/7, 2017 at 6:7 Comment(0)
S
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 = 
Scathe answered 7/1, 2018 at 6:8 Comment(1)
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.Antinucleon
B
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.

Batten answered 25/7, 2019 at 5:5 Comment(0)
B
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.

Ballista answered 17/8, 2018 at 6:47 Comment(0)
D
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)

Disturbed answered 9/2, 2019 at 11:6 Comment(3)
Is C:\Python\Python37\pythonw.exe "C:\Python\Python37\Scripts\idlex.pyw" saved as .bat on Windows?Vikki
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.Disturbed
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.Vikki

© 2022 - 2024 — McMap. All rights reserved.