How to turn on line numbers in IDLE?

Question:

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?

Asked By: User

||

Answers:

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

Answered By: ChrisProsser

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

Answered By: Davos

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.

Answered By: Martin Ghecea

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 = 
Answered By: StahlRat

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.

Answered By: Akshay Vilas Patil

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

pip install IDLEX

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

C:PythonPython37pythonw.exe "C:PythonPython37Scriptsidlex.pyw"

The paths may be different and need to be changed:

C:PythonPython37

(Thanks for the great answers above)

Answered By: Aaron

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.

Answered By: Terry Jan Reedy
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.