python console tab completion not working in windows

Question:

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.

Asked By: red888

||

Answers:

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
Answered By: John La Rooy

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.

Answered By: ShadowRanger

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

pip install pyreadline
pip install ipython
Answered By: Jayant Kumar

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')
Answered By: Soup Endless

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
Answered By: Elad
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.