Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Jupyter Notebook on my local computer to run code on a remote computer

I use Jupyter Notebook to run bioinformatic analyses, and I love it. However, it only really plays nice when I run it on my personal computer. However, I regularly do analysis using a remote computer with multiple cores to reduce processing time. I'd like to be able to use the Jupyter Notebook interface on my personal computer while everything is actually running on the remote computer. I generally do this via ssh access to the remote computer within the shell and execute all commands at the command line. I'd love to do this from the Jupyter notebook on my personal computer, rather than from the shell on my personal computer. It is relevant that I don't have sudo access on the remote computer.

So far, I've installed miniconda and jupyter notebook on the remote computer like this:

wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

Once conda is installed properly, I install jupyter notebook via miniconda with this line:

conda install jupyter

This installs successfully. I can then start a jupyter notebook session on the remote machine with the line:

jupyter notebook --no-browser

So far, so good. My next question: How do I have my local jupyter notebook connect to the remote machine, so that I can execute commands on the remote machine using my local jupyter notebook? There is some documentation here, however i have been trying different things for hours, but have failed to succeed.

Can anyone give a straight forward method to connect to my remote server, given that I am this far along? I feel like it should just be a matter of entering url addresses and passwords into my local Jupyter notebook (all of this is so easy via ssh in the shell).

like image 814
colin Avatar asked Feb 14 '16 22:02

colin


People also ask

Can you run Jupyter notebook locally?

To launch a Jupyter notebook, open your terminal and navigate to the directory where you would like to save your notebook. Then type the command jupyter notebook and the program will instantiate a local server at localhost:8888 (or another specified port).

How do I access my Jupyter notebook over the network?

Enter the password; copy the output and assign the output to the attribute c. NotebookApp. password . Now run the server and open the URL http://IP:8888 from another PC or mobile to browse notebooks after entering the correct password.


Video Answer


2 Answers

Follow the steps below:
Enable port forwarding on remote machine

ssh -N -f -L 127.0.0.1:8898:127.0.0.1:8898 [email protected]

Do ssh to your remote machine and then run following command on remote machine

jupyter-notebook --no-browser --port=8898

you will see some thing as shown below

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
http://localhost:8898/token=eaf2f51f9c053f43d8bd093e76f0cc6301b545549c998fa2&token=eaf2f51f9c053f43d8bd093e76f0cc6301b545549c998fa2

Copy and paste the URL in your local machine browser.

like image 163
Somesh Choudhary Avatar answered Dec 04 '22 17:12

Somesh Choudhary


If you want to access Jupyter/Ipython notebook running on a VPS remotely, I wrote a tutorial on the digital ocean community site.

As shown in the guide, after installing and running Ipython Notebook using command line on the server, you can connect to the notebook using SSH tunnelling with Putty (on windows) or the ssh -L command on Unix-like systems (ie Mac and Linux)

like image 40
mrandrewandrade Avatar answered Dec 04 '22 15:12

mrandrewandrade