Coder Social home page Coder Social logo

xonsh / xontrib-jupyter Goto Github PK

View Code? Open in Web Editor NEW
27.0 5.0 1.0 108 KB

Xonsh jupyter kernel allows to run Xonsh shell code in Jupyter, JupyterLab, Euporia, etc.

License: MIT License

Python 100.00%
xonsh xontrib jupyter jupyter-notebook jupyter-extension jupyterlab euporie jupyter-kernels jupyter-lab jupyter-notebook-extension

xontrib-jupyter's Introduction

Xonsh kernel for Jupyter Notebook and Jupyter Lab allows to execute xonsh shell commands in a notebook cell.

If you like the idea click ⭐ on the repo and tweet.

Installation

To install use xpip:

xpip install xontrib-jupyter
# or: xpip install -U git+https://github.com/xonsh/xontrib-jupyter

xontrib load jupyter
xonfig jupyter-kernel --help  # Options for installing.
xonfig jupyter-kernel --user  # Install kernel spec in user config directory.

Check the installation:

jupyter kernelspec list
# Available kernels:
#  python3    /opt/homebrew/lib/python3.11/site-packages/ipykernel/resources
#  xonsh      /PATH_TO_ENV_PREFIX/share/jupyter/kernels/xonsh

xontrib load jupyter
xonfig jupyter-kernel
# Installing Jupyter kernel spec:
#  root: None
#  prefix: /PATH_TO_ENV_PREFIX/
#  as user: False

xonfig info
#| jupyter          | True
#| jupyter kernel   | /PATH_TO_ENV_PREFIX/share/jupyter/kernels/xonsh

Usage

Jupyter

Just run Jupyter Notebook or JupyterLab and choose xonsh:

jupyter notebook
# or
jupyter lab

Euporie

Euporie is a terminal based interactive computing environment.

euporie-notebook --kernel-name xonsh  # or change the kernel in UI
# or
euporie-console --kernel-name xonsh  # or change the kernel in UI

Testing

  • install the project with its dependencies
poetry install
poetry install --only-root
  • now start the xonsh shell
xonsh --no-rc
  • inside the xonsh shell, you can load the jupyter xontrib and install the kernel
xontrib load jupyter

# this will install the kernel
xonfig jupyter-kernel --user

# now start a notebook and choose xonsh kernel
jupyter notebook

Releasing your package

  1. Bump the version of the package poetry version patch (or minor/major)

  2. Push the changes to the repo and publish with

    poe release
  3. The release notes are automatically generated as a draft release after each PR.

  4. Create a GitHub release from the draft release against the newly pushed tag

Known issues

Uncaptured output

In some cases you need to enable capturing first:

$XONSH_CAPTURE_ALWAYS = True
$XONSH_SUBPROC_CAPTURED_PRINT_STDERR = True

Uncaptured output because of pager

Some tools like AWS CLI using the uncapturable less pager to show the output by default. In these cases you need to find the way to disable the pager e.g. set $AWS_PAGER = 'cat' for AWS CLI.

Credits

xontrib-jupyter's People

Contributors

anki-code avatar jnoortheen avatar joouha avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

joouha

xontrib-jupyter's Issues

Error starting xonsh kernel: `xonsh.__amalgam__.XonshError: jupyter is not recognized as a shell type`

To reproduce on a Windows 11 system running Anaconda from PowerShell:

PS> conda create -n xonsh pip notebook
PS> conda activate xonsh
PS> pip install xonsh
PS> xonsh
$ xpip install xontrib-jupyter-shell
$ exit
PS> xonsh
$ xontrib load jupyter
$ xonfig jupyter-kernel
$ exit
PS> jupyter notebook

In the Jupyter session opened up by the last command, creating a new Xonsh notebook results in the following errors being written to the console:

[I 08:09:36.455 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports
Traceback (most recent call last):
  File "C:\Users\cgran\Anaconda3\envs\xonsh\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\cgran\Anaconda3\envs\xonsh\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\cgran\Anaconda3\envs\xonsh\lib\site-packages\xonsh_jupyter\kernel.py", line 504, in <module>
    main()
  File "C:\Users\cgran\Anaconda3\envs\xonsh\lib\site-packages\xonsh_jupyter\kernel.py", line 486, in main
    setup(
  File "C:\Users\cgran\Anaconda3\envs\xonsh\lib\site-packages\xonsh\__amalgam__.py", line 22484, in setup
    XSH.shell = Shell(execer, ctx=ctx, shell_type=shell_type)
  File "C:\Users\cgran\Anaconda3\envs\xonsh\lib\site-packages\xonsh\__amalgam__.py", line 15234, in __init__
    self.shell = self.construct_shell_cls(
  File "C:\Users\cgran\Anaconda3\envs\xonsh\lib\site-packages\xonsh\__amalgam__.py", line 15195, in construct_shell_cls
    raise XonshError(f"{backend} is not recognized as a shell type")
xonsh.__amalgam__.XonshError: jupyter is not recognized as a shell type

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Fix DeprecationWarning zmq in JupyterLab

Just see in log JupyterLab:

/opt/homebrew/lib/python3.11/site-packages/xonsh_jupyter/kernel.py:21: 
DeprecationWarning: zmq.eventloop.ioloop is deprecated in pyzmq 17. pyzmq now works with default tornado and asyncio eventloops.
  from zmq.eventloop import ioloop, zmqstream

/opt/homebrew/lib/python3.11/site-packages/tornado/ioloop.py:265: 
DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
xpip list | grep jupyter
jupyter                       1.0.0
jupyter_client                8.0.3
jupyter-console               6.6.3
jupyter_core                  5.3.0
jupyter-events                0.6.3
jupyter_server                2.5.0
jupyter_server_fileid         0.8.0
jupyter_server_terminals      0.4.4
jupyter_server_ydoc           0.8.0
jupyter-ydoc                  0.2.3
jupyterlab                    3.6.2
jupyterlab-pygments           0.2.2
jupyterlab_server             2.20.0
jupyterlab-widgets            3.0.5
xontrib-jupyter-shell         0.2.0

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Present xonsh to Jupyter community

I've created this issue to save the comment with the links where we can promote xonsh for Jupyter community - jupyterlab/jupyterlab#14147:

You are absolutely welcome to (in order of recommendation):

Also:

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Rename pypi package from xontrib-jupyter-shell to xontrib-jupyter

Hi @jnoortheen! Could you please rename pypi package from xontrib-jupyter-shell to xontrib-jupyter to make the name consistent.

  • repo https://github.com/xonsh/xontrib-jupyter
  • install xpip install xontrib-jupyter - instead of xontrib-jupyter-shell
  • load xontrib load jupyter

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

JupyterLab support

Hi!

The xonsh kernel for Jupyter works perfect!

But now the JupyterLab is the new trend and the kernel is not working:

/opt/miniconda/lib/python3.8/site-packages/xonsh/jupyter_kernel.py:136: 
DeprecationWarning: zmq.eventloop.ioloop is deprecated in pyzmq 17. pyzmq now works 
with default tornado and asyncio eventloops.  ioloop.install()

Please add support for JupyterLab.

Thanks!

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

`NotImplementedError` trying to start xonsh kernel in Jupyter notebook

Brand new virtual environemt containing latest-and-greatest of everything. I'm trying this for the first time in order to add it to getting-started docs.

xonfig

+------------------+----------------------+
| xonsh            | 0.9.19.dev87         |
| Git SHA          | 1c9fffed             |
| Commit Date      | Aug 16 16:31:17 2020 |
| Python           | 3.8.5                |
| PLY              | 3.11                 |
| have readline    | False                |
| prompt toolkit   | 3.0.6                |
| shell type       | prompt_toolkit       |
| pygments         | 2.6.1                |
| on posix         | False                |
| on linux         | False                |
| on darwin        | False                |
| on windows       | True                 |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
+------------------+----------------------+

pip list

Package           Version
----------------- -------
argon2-cffi       20.1.0
attrs             19.3.0
backcall          0.2.0
bleach            3.1.5
cffi              1.14.2
colorama          0.4.3
decorator         4.4.2
defusedxml        0.6.0
entrypoints       0.3
ipykernel         5.3.4
ipython           7.17.0
ipython-genutils  0.2.0
jedi              0.17.2
Jinja2            2.11.2
jsonschema        3.2.0
jupyter-client    6.1.6
jupyter-core      4.6.3
MarkupSafe        1.1.1
mistune           0.8.4
nbconvert         5.6.1
nbformat          5.0.7
notebook          6.1.3
packaging         20.4
pandocfilters     1.4.2
parso             0.7.1
pickleshare       0.7.5
pip               20.1.1
prometheus-client 0.8.0
prompt-toolkit    3.0.6
ptk               1.3.7
pycparser         2.20
Pygments          2.6.1
pyparsing         2.4.7
pyrsistent        0.16.0
python-dateutil   2.8.1
pywin32           228
pywinpty          0.5.7
pyzmq             19.0.2
Send2Trash        1.5.0
setuptools        47.1.0
six               1.15.0
terminado         0.8.3
testpath          0.4.4
tornado           6.0.4
traitlets         4.3.3
wcwidth           0.2.5
webencodings      0.5.1
wheel             0.35.1
xonsh             0.9.19

Repro

  1. python -m venv .venv-jup
  2. pip install notebook
  3. python setup.py install
    (Did this because pip install . did not run install_jupyter_hook).
  4. cd <notebooks>
  5. jupyter notebook
  6. Switch to browser, open notebook page
  7. Open new notebook, select kernel xonsh, as expected
  8. In first cell, enter xonfig

Expect

To see output from xonsh command in cell.

Observe

On notebook page, kernel status hangs at "Kernel starting, please wait"

Traceback

PS C:\Users\bobhy\work\nb> C:\Users\bobhy\src\xonsh\.venv-jup\Scripts\activate.ps1
(.venv-jup) PS C:\Users\bobhy\work\nb> jupyter notebook
[I 01:51:13.987 NotebookApp] Serving notebooks from local directory: C:\Users\bobhy\work\nb
[I 01:51:13.988 NotebookApp] Jupyter Notebook 6.1.3 is running at:
[I 01:51:13.988 NotebookApp] http://localhost:8888/?token=3ad07542ebdacb6928d66ac7ebc739b7d959c74b1856d6d3
[I 01:51:13.989 NotebookApp]  or http://127.0.0.1:8888/?token=3ad07542ebdacb6928d66ac7ebc739b7d959c74b1856d6d3
[I 01:51:13.989 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 01:51:14.248 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/bobhy/AppData/Roaming/jupyter/runtime/nbserver-14856-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=3ad07542ebdacb6928d66ac7ebc739b7d959c74b1856d6d3
     or http://127.0.0.1:8888/?token=3ad07542ebdacb6928d66ac7ebc739b7d959c74b1856d6d3
[I 01:51:34.385 NotebookApp] Creating new notebook in
[I 01:51:43.399 NotebookApp] Kernel started: 2d72feed-9e3d-4044-8da2-4bc7b9df9190, name: xonsh
[W 01:51:43.475 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js (::1) 25.00ms referer=http://localhost:8888/notebooks/Untitled1.ipynb?kernel_name=xonsh
C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\xonsh\jupyter_kernel.py:137: DeprecationWarning: zmq.eventloop.ioloop is deprecated in pyzmq 17. pyzmq now works with default tornado and asyncio eventloops.
  ioloop.install()
Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\xonsh\jupyter_kernel.py", line 478, in <module>
    kernel.start()
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\xonsh\jupyter_kernel.py", line 155, in start
    self.iopub_stream = zmqstream.ZMQStream(self.iopub_socket)
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\zmq\eventloop\zmqstream.py", line 127, in __init__
    self._init_io_state()
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\zmq\eventloop\zmqstream.py", line 552, in _init_io_state
    self.io_loop.add_handler(self.socket, self._handle_events, self.io_loop.READ)
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\tornado\platform\asyncio.py", line 100, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "C:\Program Files\Python38\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError
[I 01:52:13.391 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\xonsh\jupyter_kernel.py:137: DeprecationWarning: zmq.eventloop.ioloop is deprecated in pyzmq 17. pyzmq now works with default tornado and asyncio eventloops.
  ioloop.install()
Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\xonsh\jupyter_kernel.py", line 478, in <module>
    kernel.start()
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\xonsh\jupyter_kernel.py", line 155, in start
    self.iopub_stream = zmqstream.ZMQStream(self.iopub_socket)
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\zmq\eventloop\zmqstream.py", line 127, in __init__
    self._init_io_state()
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\zmq\eventloop\zmqstream.py", line 552, in _init_io_state
    self.io_loop.add_handler(self.socket, self._handle_events, self.io_loop.READ)
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\tornado\platform\asyncio.py", line 100, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "C:\Program Files\Python38\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError
[I 01:52:31.410 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\xonsh\jupyter_kernel.py", line 464, in <module>
    setup(
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\xonsh\__amalgam__.py", line 24603, in setup
    execer = Execer(xonsh_ctx=ctx)
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\xonsh\__amalgam__.py", line 23448, in __init__
    load_builtins(execer=self, ctx=xonsh_ctx)
  File "C:\Users\bobhy\src\xonsh\.venv-jup\lib\site-packages\xonsh\__amalgam__.py", line 23166, in load_builtins
[I 01:52:34.282 NotebookApp] Interrupted...
[I 01:52:34.340 NotebookApp] Shutting down 1 kernel
...

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

PYPI release

Hi! Thank you for the awesome xontrib! I gave it a star!

I've found that ...

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Add topics

Hi @jnoortheen !

Please add jupyter and jupyterlab topics to this repository.

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Set the social image

Hi @jnoortheen !

  1. Please set the social image for the repo (below)
  2. Please make the new release

Thanks!

image

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

ipython display not working in xonsh cells

Hi!

IPython widgets not working in xonsh v0.14.1, xontrib-jupyter v0.3.0 and JupyterLab v4.0.7. Below you can observe the result as it's returned by a xonsh cell

imagen

Next, same code basically but different outcome with a Python kernel.

imagen

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.