You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constitute about 1/3 (0.3–0.4s total on my system) of the total startup time for the getting_started example — what is noticeable.
I’m a bit puzzled by these lines, because start_ipython is only used in the do_ipy method of the Cmd class. However, inside this method, the function is imported again (B):
# Allow users to install ipython from a cmd2 prompt when needed and still have ipy command worktry:
_dummy=start_ipython# noqa: F823exceptNameError:
fromIPythonimportstart_ipython
At least on my linux system, removing lines (A) and only importing start_ipython (instead of (B)) doesn’t change anything, and it reduces the startup time as mentioned above.
I understand the comment in (B) that the intended purpose of this setup is that installing ipython from within a running cmd2 app (for example, via the !pip install ipython command) should make ipython usable without closing the app. Do I understand this correctly?
However, with or without the changes described above, this still seems possible for me—at least on Linux—when using a virtual environment with uv or pip directly.
Possible solution
The changes described above. However I cannot test whether they break anything on a different system like window, for example.
Additional note
I think it would be reasonable to provide ipython as its own optional dependency group in the pyproject.toml file.
That first import is a relic of a bug fix in 2024.
The comment for it was: When using gnureadline with Python 3.13, start_ipython needs to be imported before any readline-related stuff
During the conversion to prompt-toolkit, it looks like we removed the comment but left the import. I'm pretty sure we can remove it.
There is 1 remaining case where gnureadline could be imported and that's when we enable tab completion in the py shell. I'll set up a 3.13 test environment later and see what happens if we remove the first start_ipython import.
Activity
kmvanbrunt commentedon Jul 16, 2026
That first import is a relic of a bug fix in 2024.
The comment for it was:
When using gnureadline with Python 3.13, start_ipython needs to be imported before any readline-related stuffDuring the conversion to
prompt-toolkit, it looks like we removed the comment but left the import. I'm pretty sure we can remove it.There is 1 remaining case where
gnureadlinecould be imported and that's when we enable tab completion in thepyshell. I'll set up a 3.13 test environment later and see what happens if we remove the firststart_ipythonimport.kmvanbrunt commentedon Jul 16, 2026
For reference, here is the PR where that first
start_ipythonimport was introduced.#1358