ipython: NameError: name 'sys' is not defined

Got the below error when I use this code snipets,

In [1]: from elasticsearch import Elasticsearch
In [2]: es = Elasticsearch(hosts=[{"host": "host.docker.internal", "port": 9200}],
   ...:                     max_retries=30,
   ...:                     retry_on_timeout=True,
   ...:                     request_timeout=30)
In [3]: es.info()

Error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/IPython/terminal/ptutils.py", line 113, in get_completions
    yield from self._get_completions(body, offset, cursor_position, self.ipy_completer)
  File "/usr/local/lib/python3.8/site-packages/IPython/terminal/ptutils.py", line 129, in _get_completions
    for c in completions:
  File "/usr/local/lib/python3.8/site-packages/IPython/core/completer.py", line 438, in _deduplicate_completions
    completions = list(completions)
  File "/usr/local/lib/python3.8/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 "/usr/local/lib/python3.8/site-packages/IPython/core/completer.py", line 1861, in _completions
    matched_text, matches, matches_origin, jedi_matches = self._complete(
  File "/usr/local/lib/python3.8/site-packages/IPython/core/completer.py", line 2029, in _complete
    completions = self._jedi_matches(
  File "/usr/local/lib/python3.8/site-packages/IPython/core/completer.py", line 1373, in _jedi_matches
    interpreter = jedi.Interpreter(
  File "/usr/local/lib/python3.8/site-packages/jedi/api/__init__.py", line 725, in __init__
    super().__init__(code, environment=environment,
TypeError: __init__() got an unexpected keyword argument 'column'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/shell.py", line 100, in handle
    return getattr(self, shell)(options)
  File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/shell.py", line 36, in ipython
    start_ipython(argv=[])
  File "/usr/local/lib/python3.8/site-packages/IPython/__init__.py", line 126, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/traitlets/config/application.py", line 845, in launch_instance
    app.start()
  File "/usr/local/lib/python3.8/site-packages/IPython/terminal/ipapp.py", line 356, in start
    self.shell.mainloop()
  File "/usr/local/lib/python3.8/site-packages/IPython/terminal/interactiveshell.py", line 564, in mainloop
    self.interact()
  File "/usr/local/lib/python3.8/site-packages/IPython/terminal/interactiveshell.py", line 547, in interact
    code = self.prompt_for_code()
  File "/usr/local/lib/python3.8/site-packages/IPython/terminal/interactiveshell.py", line 473, in prompt_for_code
    text = self.pt_app.prompt(
  File "/usr/local/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 1013, in prompt
    return self.app.run(set_exception_handler=set_exception_handler)
  File "/usr/local/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 816, in run
    return loop.run_until_complete(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 783, in run_async
    return await _run_async2()
  File "/usr/local/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 771, in _run_async2
    await self.cancel_and_wait_for_background_tasks()
  File "/usr/local/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 872, in cancel_and_wait_for_background_tasks
    await task
  File "/usr/local/lib/python3.8/site-packages/prompt_toolkit/buffer.py", line 1854, in new_coroutine
    await coroutine(*a, **kw)
  File "/usr/local/lib/python3.8/site-packages/prompt_toolkit/buffer.py", line 1683, in async_completer
    async for completion in self.completer.get_completions_async(
  File "/usr/local/lib/python3.8/site-packages/prompt_toolkit/completion/base.py", line 269, in get_completions_async
    async for completion in completer.get_completions_async(
  File "/usr/local/lib/python3.8/site-packages/prompt_toolkit/completion/base.py", line 196, in get_completions_async
    for item in self.get_completions(document, complete_event):
  File "/usr/local/lib/python3.8/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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 139
  • Comments: 22 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Ok that was easy. The Jedi release on 12/25 version 0.18.0 is breaking tab completion. pip install --upgrade 'jedi<0.18.0' gets you going.

For those looking for a quick fix, here’s @duysqubix’s answer, distilled into a command:
    pip install -U jedi==0.17.2 parso==0.7.1

Ugh, can we please stop re-posting the solution and trying to take credit where credit is not due. The bleeding has stopped, a fix has been put in by @yurzo there is no need to re-post the fix.

When is a release with the fix coming?

I found the culprit, it seems that installing a fresh ipython package pulls over the recent jedi==0.18.0 and parso==0.8.1 I downgraded jedi to 0.17.2 and parso 0.7.1 and this error went away.

Not sure of the overall fix, but hopefully this helps anyone for a temp solution. also this solution is found in #12740

@duysqubix solved for me, jedi==0.17.2 and parson==0.7.1

Thank you all who helped triage this problem and for providing workarounds while multiple fixes were in place. I’m grateful to the python community with how collaborative everyone can be to fix issues. I’ve also confirmed it’s working for me.

Thanks again for the all the hard work and keep on kicking butt. I love this tool.

detectable with flake8

flake8 IPython/terminal/ptutils.py | grep F821
IPython/terminal/ptutils.py:116:51: F821 undefined name 'sys'
IPython/terminal/ptutils.py:117:21: F821 undefined name 'traceback'

backport PR is merged re-closing. I’ll start the release in a few minutes.

Hum that is quite probable that another fix for jedi was not backported. I’ll try to find it. I haven’t had time to finish the release today but maybe tomorrow.

Many thanks for reporting and testing on both 7.x and master.

Might be one of 387da044fc or 95ab5c53c0 , or both.

The actual missing imports for sys andtraceback that compounded the Jedi problem were also fixed here and here (h/t @Carreau)

I get same issue with auto-completion

Python 3.9.1 (default, Dec 16 2020, 01:02:01) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
<IPython.terminal.interactiveshell.TerminalInteractiveShell object at 0x7f924ddd0100>
Using matplotlib backend: Qt5Agg
Populating the interactive namespace from numpy and matplotlib


Unhandled exception in event loop:
  File "/home/alex/Python/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/alex/Python/lib/python3.9/site-packages/prompt_toolkit/input/vt100.py", line 169, in callback_wrapper
    callback()
  File "/home/alex/Python/lib/python3.9/site-packages/prompt_toolkit/application/application.py", line 666, in read_from_input
    self.key_processor.process_keys()
  File "/home/alex/Python/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 274, in process_keys
    self._process_coroutine.send(key_press)
  File "/home/alex/Python/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 186, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "/home/alex/Python/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 329, in _call_handler
    handler.call(event)
  File "/home/alex/Python/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 101, in call
    self.handler(event)
  File "/home/alex/Python/lib/python3.9/site-packages/prompt_toolkit/key_binding/bindings/completion.py", line 65, in display_completions_like_readline
    completions = list(b.completer.get_completions(b.document, complete_event))
  File "/home/alex/Python/lib/python3.9/site-packages/IPython/terminal/ptutils.py", line 116, in get_completions
    exc_type, exc_value, exc_tb = sys.exc_info()

Exception name 'sys' is not defined

Posted a pr to pin the dependency #12746

Line completion now for me in 7.20.0. Thanks a lot!

d<tab>

Python 3.9.1 (default, Dec 16 2020, 01:02:01) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.20.0 -- An enhanced Interactive Python. Type '?' for help.
Using matplotlib backend: Qt5Agg
Populating the interactive namespace from numpy and matplotlib

In [1]: d
date2num()          degrees             detrend_linear      diff                docstring           dtype               
datestr2num         del                 detrend_mean        digitize            dot                 %debug              
datetime            delattr             detrend_none        dir                 double              %%debug             
datetime64          delaxes             diag                dirichlet           drange              develop/            
datetime_as_string  delete              diag_indices        disconnect          draw                %dhist              
datetime_data       deprecate           diag_indices_from   disp                draw_all            %dirs               
def                 deprecate_with_doc  diagflat            display             draw_if_interactive %doctest_mode       
default_rng         det                 diagonal            divide              dsplit              dumps/              
deg2rad             detrend             dict                divmod              dstack              
In [1]: d