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)
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 parso0.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
andparson==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
This looks like a duplicate of https://github.com/ipython/ipython/issues/12740.
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
Posted a pr to pin the dependency #12746
Line completion now for me in 7.20.0. Thanks a lot!
d<tab>