简体   繁体   中英

python console tab completion not working in windows

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:

在此处输入图像描述

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.

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

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

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.

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

pip install pyreadline
pip install ipython

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交互窗口


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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM