Calysto / xonsh_kernel

Jupyter Kernel for Xonsh
22 stars 2 forks source link

xonsh kernel Module 'builtins' has no attribute __xonsh_shell__ #13

Open BoPeng opened 4 years ago

BoPeng commented 4 years ago

MacOSX, python 3.7, xonsh-0.9.13.dev1, xonsh-kernel-0.4.1, starting jupyter notebook, enter ls, notebook hangs with the following error message displayed in console

/Users/bpeng1/anaconda3/envs/sos/lib/python3.7/site-packages/ipykernel/iostream.py:14: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  from imp import lock_held as import_lock_held
/Users/bpeng1/anaconda3/envs/sos/lib/python3.7/site-packages/ipykernel/kernelapp.py:523: DeprecationWarning: zmq.eventloop.ioloop is deprecated in pyzmq 17. pyzmq now works with default tornado and asyncio eventloops.
  zmq_ioloop.install()
/Users/bpeng1/anaconda3/envs/sos/lib/python3.7/site-packages/jupyter_client/connect.py:401: DeprecationWarning: IPKernelApp._ip_changed is deprecated in traitlets 4.1: use @observe and @unobserve instead.
  def _ip_changed(self, name, old, new):
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
  File "/Users/bpeng1/anaconda3/envs/sos/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 268, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "/Users/bpeng1/anaconda3/envs/sos/lib/python3.7/site-packages/tornado/gen.py", line 735, in run
    value = future.result()
  File "/Users/bpeng1/anaconda3/envs/sos/lib/python3.7/site-packages/tornado/gen.py", line 209, in wrapper
    yielded = next(result)
  File "/Users/bpeng1/anaconda3/envs/sos/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 541, in execute_request
    user_expressions, allow_stdin,
  File "/Users/bpeng1/anaconda3/envs/sos/lib/python3.7/site-packages/metakernel/_metakernel.py", line 395, in do_execute
    retval = self.do_execute_direct(code)
  File "/Users/bpeng1/anaconda3/envs/sos/lib/python3.7/site-packages/xonsh_kernel/kernel.py", line 45, in do_execute_direct
    out, err, interrupted = self._do_execute_direct(code)
  File "/Users/bpeng1/anaconda3/envs/sos/lib/python3.7/site-packages/xonsh_kernel/kernel.py", line 60, in _do_execute_direct
    shell = builtins.__xonsh_shell__
AttributeError: module 'builtins' has no attribute '__xonsh_shell__'
[I 11:20:59.737 NotebookApp] Saving file at /Untitled1.ipynb
WardThomas commented 4 years ago

similar issues are found with ipython on Debian 10, python 3.7 , xonsh_kernel installed via pipenv

pipenv install xonsh_kernel pipenv shell python -m xonsh_kernel.install ipython console --kernel calysto_xonsh

In [1]: echo "ddd" :
[IPKernelApp] ERROR | Exception in message handler: Traceback (most recent call last): File "/home//.local/share/virtualenvs/-bk1jwvoh/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 268, in dispatch_shell yield gen.maybe_future(handler(stream, idents, msg)) File "/home//.local/share/virtualenvs/-bk1jwvoh/lib/python3.7/site-packages/tornado/gen.py", line 735, in run value = future.result() File "/home//.local/share/virtualenvs/-bk1jwvoh/lib/python3.7/site-packages/tornado/gen.py", line 209, in wrapper yielded = next(result) File "/home//.local/share/virtualenvs/-bk1jwvoh/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 541, in execute_request user_expressions, allow_stdin, File "/home//.local/share/virtualenvs/-bk1jwvoh/lib/python3.7/site-packages/metakernel/_metakernel.py", line 395, in do_execute retval = self.do_execute_direct(code) File "/home//.local/share/virtualenvs/-bk1jwvoh/lib/python3.7/site-packages/xonsh_kernel/kernel.py", line 45, in do_execute_direct out, err, interrupted = self._do_execute_direct(code) File "/home//.local/share/virtualenvs/-bk1jwvoh/lib/python3.7/site-packages/xonsh_kernel/kernel.py", line 60, in _do_execute_direct shell = builtins.xonsh_shell AttributeError: module 'builtins' has no attribute 'xonsh_shell'

scopatz commented 4 years ago

__xonsh_shell__ was renamed to __xonsh__.shell many versions ago. That should be the only update (and similar renames) that is needed. The deprecation warnings and proxies were removed in v0.9.9: https://xon.sh/changelog#v0-9-9

BoPeng commented 4 years ago
$ pip list | grep xon
xonsh                  0.9.13.dev1 
xonsh-kernel           0.4.1       

So the problem should be with xonsh-kernel, which has not been updated with the newer versions of xonsh.

WardThomas commented 4 years ago

Hello BoPeng, thanks for following that up

I have manged to get the Calysto/xonsh_kernel to work with Jupyter lab

I updated python3.7/site-packages/xonsh_kernel/kernel.py on my machine by replacing all occurrences of

and jupyter lab now works with the Calysto/xonsh_kernel t

I left these statements as is swap(builtins, 'xonsh_stdout_uncaptured', out), \ swap(builtins, 'xonsh_stderr_uncaptured', err), \

but they might need changing to swap(builtins, 'xonsh.stdout_uncaptured', out), \

here is my modified kernel.py file

kernel.TXT swap(builtins, 'xonsh.stderr_uncaptured', err), \

regards

BoPeng commented 4 years ago

@WardThomas Could you please create a PR? @blink1073 would be happy to take a look and merge it, even add you as a maintainer of the project.

blink1073 commented 4 years ago

Seconded :smile: