ptpython is an advanced, cross-platform Python REPL (Read-Eval-Print Loop) built on top of the prompt_toolkit library. It provides features like syntax highlighting, autocompletion, multiline editing, mouse support, and customizable key bindings (Emacs and Vi modes). Currently at version 3.0.32, it sees fairly frequent updates, often with several patch releases per month.
pip install ptpythonVerified import paths — ran on the pinned version, not inferred.
To start a `ptpython` shell, simply run `ptpython` in your terminal. To embed it in a Python script for debugging or interactive sessions, use `ptpython.repl.embed()`. You should pass `globals()` and `locals()` to `embed()` to make the current scope available inside the REPL.
Upgrade to Python 3.8 or newer, or pin ptpython to <3.0.30.
Explicitly load your configuration using `from ptpython.repl import run_config; run_config(repl, config_path)` within your `configure` callback passed to `embed()`.
Ensure you explicitly pass `--asyncio` when you intend to use the asyncio-enabled REPL for top-level await or other async features.
Be aware that both `exit` and `exit()` will work to leave the embedded REPL.
If the default theme's colors are unsatisfactory, you can configure a custom color scheme in your `config.py` file or select a different theme if available.
Downgrade `prompt_toolkit` to a compatible version, or upgrade `ptpython` to a version that supports your `prompt_toolkit` version. Often, reinstalling `ptpython` in a clean virtual environment resolves such dependency conflicts.
Ensure you have activated the correct virtual environment before launching `ptpython`, or install the missing module using `pip install some_module` within the environment that `ptpython` is using. You can inspect `sys.path` within the `ptpython` REPL to verify the paths being searched for modules.
Disable flow control in your terminal by running the command `stty -ixon`. This command is usually executed in your shell before starting `ptpython`.
Review your code to confirm the object (`X`) is of the expected type and that the attribute or method (`Y`) you are trying to access exists and is spelled correctly. In `ptpython`, you can use `dir(X)` to see available attributes or `help(X)` to view documentation for the object.