43

running Windows 10

From what I understand python3 has tab completion in the python console already built in but this isn't working for me.

When I hit tab there is no completion:

enter image description here

Im aware there are modules that can do this, but I'd like to use the native feature if it is available to me on windows.

2
  • did you try hitting the tab twice? Usually, it will give you list of available commands
    – yash
    Oct 26, 2017 at 1:01
  • 4
    no tab inserts an actual tab
    – red888
    Oct 26, 2017 at 1:03

5 Answers 5

60

The builtin completion relies on the GNU readline library.

You may be able to get completion working by installing the python version (pyreadline) of this package on Windows.

python -m pip install pyreadline
4
  • 8
    Don't understand why this is not part of the site-package for Windows then, license issue?
    – kakyo
    Jun 13, 2019 at 6:41
  • 3
    Fixes the issue but I can't insert tabs anymore. Not even for running a simple for loop Mar 4, 2020 at 19:02
  • 1
    I came here looking for a solution that works with the cmd module on windows 10. pyreadline works well with the cmd module in powershell (although Rochak is correct about tabs), but it's really clumsy to use in git bash and just buggy in interactive mode (python -i). The package also doesn't seem to have been updated in a long time.
    – DavidW
    Nov 27, 2020 at 9:23
  • 2
    @DavidW: Answering why the "package also doesn't seem to have been updated in a long time": pyreadline was initially developed to support IPython (which used it through the 4.x releases). But as of IPython 5.0, they moved to using prompt_toolkit (which is much more full-featured and platform independent), and it's pretty clear that once they made that decision, they stopped updating pyreadline (pyreadline was last updated in September, 2015, a month after IPython 4.0 released; IPython 5.0 released nine months later). Mar 30, 2021 at 16:42
24

The original pyreadline is no longer maintained and doesn't work on newer versions of Python (>=3.10). Installing pyreadline3 works:

python -m pip install pyreadline3
2
  • 1
    This is the most up to date! Worked!
    – kyrlon
    Feb 22 at 18:21
  • adding pyreadline3; sys_platform == "win32" to my requirements.txt file was great when dealing with multiple different OS.
    – kyrlon
    Feb 22 at 18:37
7

I'd discourage use of pyreadline where possible, as it was written to support IPython, and stopped active development when IPython stopped using readline/pyreadline to support their REPL.

As an alternative, I'd suggest IPython itself; it implements their own tab-completion features (using prompt_toolkit as of 5.0) that work in a terminal agnostic fashion. If you install and use ipython, you'll get tab completion and the host of other features it provides to improve the interactive experience. Using the py.exe manager application bundled with modern Python, install it for Python 3 (in an admin elevated command prompt if Python installed for all users) with:

py -3 -mpip install ipython

then to run it:

py -3 -mIPython

If you don't want the whole of ipython just to get these features, the prompt_toolkit folks do provide a minimalist ptpython REPL that is basically "Python with a REPL provided by prompt_toolkit" without all the other IPython bells and whistles.

2
  • pyreadline still seems to work for Python 3.9. Is your objection to it pragmatic or ideological? Apr 9, 2021 at 3:11
  • 1
    @CraigMcQueen: pyreadline is attempting to emulate readline and it does the job just barely well enough to make IPython "not the worst". It's been ages since I used it on Windows, but I remember finding it incredibly frustrating when little things didn't work quite the way they did on a native readline system (basically always for the worse). The switch to prompt_toolkit was a major improvement. Apr 9, 2021 at 10:07
1

Installing following packages should fix this on both python CLI and pyspark shell.

pip install pyreadline
pip install ipython
1
  • I used pyreadline3 instead of pyreadline, as the latter is deprecated. I have installed python for WIndows 10 64 bit, run it from powershell, and this fixed <TAB> to auto-complete.
    – PfunnyGuy
    May 11 at 20:06
-3

For Windows consider to use free Visual Studio Community as Python IDE - it has all autocomplete features out of the box for Python shell (Python Interactive Window) you will likely need: for modules, methods, etc.

In below example I've imported my DiveIntoPython.py, once I did it, the name of the module is now into autocomplete suggestions.

Python Interactive Window


If you want to add your own modules paths automatically you should utilize built-in site module as described by odjo: https://stackoverflow.com/a/59411635/2170898 -> just create sitecustomize.py file inside site.USER_SITE dir with this content (don't forget to change actual path):

import site
site.addsitedir(r'C:\My_Projects')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.