49

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 Commented Oct 26, 2017 at 1:01
  • 4
    no tab inserts an actual tab Commented Oct 26, 2017 at 1:03

6 Answers 6

63

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

Edit: For more recent Python releases, see Craig McQueen's comment below. ie. pyreadline3 instead of pyreadline

Sign up to request clarification or add additional context in comments.

5 Comments

Don't understand why this is not part of the site-package for Windows then, license issue?
Fixes the issue but I can't insert tabs anymore. Not even for running a simple for loop
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: 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).
I see an error when I try to install pyreadline with Python 3.12. See python.exe on Windows 10 with Python 3.10 errors after this module is installed · Issue #73 · pyreadline/pyreadline. Installing pyreadline3 instead seems to work.
35

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 Comments

This is the most up to date! Worked!
adding pyreadline3; sys_platform == "win32" to my requirements.txt file was great when dealing with multiple different OS.
8

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 Comments

pyreadline still seems to work for Python 3.9. Is your objection to it pragmatic or ideological?
@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.
1

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

pip install pyreadline
pip install ipython

1 Comment

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.
1

From the changelog of Python 3.13.0 beta 2, looks like tab completion has been officially added for Python REPL in Windows:

gh-111201: Add support for new pyrepl on Windows

As long as you are running Python 3.13+, completion along with other common CLI features (e.g. history, ctrl+r) will be available with the new pyrepl.

Comments

-4

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')

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.