Commands to connect linux server to jupyter notebook on web browser for easier coding life
Install Jupyter notebook
Install jupyter notebook on the server by simply run1
pip install jupyter
Run in background session
If you want to run it as a background session, run1
screen -S jupyter-on-fly
and press Ctrl+a+d to detach
Password setting and conncetion
Set password
1 | jupyter notebook --generate-config |
and you’re on the right path if it shows the following1
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json
Connect server to notebook1
jupyter notebook --ip=[server_ip_address] --port=8888 --allow-root --no-browser
For example1
jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root --no-browser
Connect to web browser
Use your webbrowser to connect
http://[server_ip_address]:8888/
and type the password you set at the previous step
Import virtual environment
If you wish to use any virtual environment in Jupyter notebook, first intall ipykernel1
2pip install --user ipykernel
python -m ipykernel install --user --name=[your-env-name]
It should print this if you do it correctly1
Installed kernelspec [your-env-name] in ~/jupyter/kernels/[your-env-name]
You will be able to see something like this (for me I have virtual environment called “rdenv” for rdkit)
If you want to uninstall, just simply write1
2pip install --user ipykernel
jupyter kernelspec uninstall [your-env-name]
(Optional) connect the server from other IP address
If you want to login this notebook with any IP, find jupyter_notebook_config.py at ~/.jupyter
and change the following line (around line 204):1
2c.NotebookApp.allow_origin = '*' # line 48
c.NotebookApp.ip = '0.0.0.0' # line 204