-->

How can the terminal in Jupyter automatically run

2020-08-09 09:09发布

问题:

I love the terminal feature and works very well for our use case where I would like students to do some work directly from a terminal so they experience that environment. The shell that launches automatically is sh and does not pick up all of my bash defaults. I can type "bash" and everything works perfectly. How can I make "bash" the default?

回答1:

Jupyter uses the environment variable $SHELL to decide which shell to launch. If you are running jupyter using init then this will be set to dash on Ubuntu systems. My solution is to export SHELL=/bin/bash in the script that launches jupyter.



回答2:

I have tried the ultimate way of switching system-wide SHELL environment variable by adding the following line to the file /etc/environment:

    SHELL=/bin/bash

This works on Ubuntu environment. Every now and then, the SHELL variable always points to /bin/bash instead of /bin/sh in Terminal after a reboot.

Also, setting up CRON job to launch jupyter notebook at system startup triggered the same issue on jupyter notebook's Terminal.

It turns out that I need to include variable setting and sourcing statements for Bash init file like ~/.bashrc in CRON job statement as follows via the command $ crontab -e :

    @reboot source /home/USERNAME/.bashrc && \
            export SHELL=/bin/bash && \
            /SOMEWHERE/jupyter notebook --port=8888

In this way, I can log in the Ubuntu server via a remote web browser (http://server-ip-address:8888/) with opening jupyter notebook's Terminal default to Bash as same as local environment.



回答3:

You can add this to your jupyter_notebook_config.py

c.NotebookApp.terminado_settings = {'shell_command': ['/bin/bash']}


回答4:

With Jupyter running on Ubuntu 15.10, the Jupyter shell will default into /bin/sh which is a symlink to /bin/dash.

rm /bin/sh
ln -s /bin/bash /bin/sh

That fix got Jupyter terminal booting into bash for me.



标签: jupyter