Ipython: crash error

Created on 20 Jan 2021  ·  4Comments  ·  Source: ipython/ipython

In [3]: nn.relu
Traceback (most recent call last):
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/terminal/ptutils.py", line 113, in get_completions
yield from self._get_completions(body, offset, cursor_position, self.ipy_completer)
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/terminal/ptutils.py", line 129, in _get_completions
for c in completions:
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/core/completer.py", line 438, in _deduplicate_completions
completions = list(completions)
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/core/completer.py", line 1818, in completions
for c in self._completions(text, offset, _timeout=self.jedi_compute_type_timeout/1000):
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/core/completer.py", line 1862, in _completions
full_text=full_text, cursor_line=cursor_line, cursor_pos=cursor_column)
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/core/completer.py", line 2030, in _complete
cursor_pos, cursor_line, full_text)
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/core/completer.py", line 1374, in _jedi_matches
text[:offset], namespaces, column=cursor_column, line=cursor_line + 1)
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/jedi/api/__init__.py", line 726, in __init__
project=Project(Path.cwd()), **kwds)
TypeError: __init__() got an unexpected keyword argument 'column'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/hcl/miniconda3/envs/pytorch/bin/ipython", line 8, in
sys.exit(start_ipython())
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/__init__.py", line 126, in start_ipython
return launch_new_instance(argv=argv, *kwargs)
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/traitlets/config/application.py", line 845, in launch_instance
app.start()
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/terminal/ipapp.py", line 356, in start
self.shell.mainloop()
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 564, in mainloop
self.interact()
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 547, in interact
code = self.prompt_for_code()
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 475, in prompt_for_code
*
self._extra_prompt_options())
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 1013, in prompt
return self.app.run(set_exception_handler=set_exception_handler)
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 817, in run
self.run_async(pre_run=pre_run, set_exception_handler=set_exception_handler)
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 783, in run_async
return await _run_async2()
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 771, in _run_async2
await self.cancel_and_wait_for_background_tasks()
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 872, in cancel_and_wait_for_background_tasks
await task
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/prompt_toolkit/buffer.py", line 1854, in new_coroutine
await coroutine(a, *kw)
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/prompt_toolkit/buffer.py", line 1684, in async_completer
document, complete_event
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/prompt_toolkit/completion/base.py", line 270, in get_completions_async
document, complete_event
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/prompt_toolkit/completion/base.py", line 196, in get_completions_async
for item in self.get_completions(document, complete_event):
File "/home/hcl/miniconda3/envs/pytorch/lib/python3.7/site-packages/IPython/terminal/ptutils.py", line 116, in get_completions
exc_type, exc_value, exc_tb = sys.exc_info()
NameError: name 'sys' is not defined

If you suspect this is an IPython 7.19.0 bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at [email protected]

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True

Most helpful comment

Reading the traceback:

  1. The sys and traceback imports are missing in IPython/terminal/ptutils.py, and this is the problem that causes the Ipython crash;
  2. In jedi/api/__init__.py, it complains that the "column" argument is passed to Script.__init__, which does not accept such argument;
  3. This error comes from IPython/core/completer.py, where at line 1373 a new jedi.Interpreter is created, passing a "column" argument to it, which chokes it.

The way to create a Script object has changed between jedi 0.17 and jedi 0.18:
In 0.17:

     def __init__(self, code=None, line=None, column=None, path=None,                                    
                 encoding=None, sys_path=None, environment=None,                                               
                 project=None, source=None):

in 0.18:

    def __init__(self, code=None, *, path=None, environment=None, project=None):

If you install jedi 0.17 instead of jedi 0.18 the current version of ipython should work.
This worked for me:

pip uninstall jedi
pip install jedi==0.17.2

All 4 comments

This issue's root not due to ipython. Actually coming from jedi package. But ipython also has an error related to this. sys module not imported in get_completions exception.

sys and traceback modules added 7 months ago but not updated in pypi. Because of this, this error not related to ipython. It's error in jedi.

Could you please give some more detailed info on why this is an issue in jedi?
Latest ipython release on PyPI is 7.19.0 which contains the missing import that is - as you already noted - fixed on master but not released.
https://github.com/ipython/ipython/blob/7.19.0/IPython/terminal/ptutils.py

No import of sys
https://github.com/ipython/ipython/blob/223e783c447a773a497809646ca0d874ea10ceeb/IPython/terminal/ptutils.py#L20-L24

Usage of sys
https://github.com/ipython/ipython/blob/223e783c447a773a497809646ca0d874ea10ceeb/IPython/terminal/ptutils.py#L116

Reading the traceback:

  1. The sys and traceback imports are missing in IPython/terminal/ptutils.py, and this is the problem that causes the Ipython crash;
  2. In jedi/api/__init__.py, it complains that the "column" argument is passed to Script.__init__, which does not accept such argument;
  3. This error comes from IPython/core/completer.py, where at line 1373 a new jedi.Interpreter is created, passing a "column" argument to it, which chokes it.

The way to create a Script object has changed between jedi 0.17 and jedi 0.18:
In 0.17:

     def __init__(self, code=None, line=None, column=None, path=None,                                    
                 encoding=None, sys_path=None, environment=None,                                               
                 project=None, source=None):

in 0.18:

    def __init__(self, code=None, *, path=None, environment=None, project=None):

If you install jedi 0.17 instead of jedi 0.18 the current version of ipython should work.
This worked for me:

pip uninstall jedi
pip install jedi==0.17.2
Was this page helpful?
0 / 5 - 0 ratings