Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect IPython Console to an kernel on the internet

Tags:

python

ipython

I have been struggling to get this working. I have followed the online stuff I could find but have been unsuccessful e.g: Ipython Documentation

I am trying to connect an IPython QTConsole on my local machine (laptop) to an IPython kernel running on a Linode cloud server on the internet.

I am not worried about security for now and just need the simplist way to do this.

I know I can start a kernel on the remote (Linode server ) using somethign like:

Ipython kernel --ip=0.0.0.0

Once i run this I can note down the kernel-xxxx.json file and I also know were to find it on the remote machine. Using the 0.0.0.0 notation I understand that the kernel will listen for outside connections.

I am just not sure how to connect to it from my local machine (Laptop)

Lets say

Remote machine  IP adres = aa.bb.cc.dd
Remote machine  Login name = root
Remote machine  hostname = dummyname

Local machine (Laptop)

 IPAdress = qq.ww.ee.rr

I can see the server and ssh to it normally e.g.

ssh [email protected]

Can anybody please help me with the ipython command line to connect to this remote kernel from my laptop?

like image 287
Tooblippe Avatar asked Aug 09 '13 12:08

Tooblippe


People also ask

How do I use IPython console?

The IPython Console allows you to execute commands and interact with data inside IPython interpreters. To launch a new IPython instance, go to New console (default settings) under the Consoles menu, or use the keyboard shortcut Ctrl - T ( Cmd - T on macOS) when the console is focused.

What is a kernel IPython?

The IPython kernel is the Python execution backend for Jupyter. The Jupyter Notebook and other frontends automatically ensure that the IPython kernel is available. However, if you want to use a kernel with a different version of Python, or in a virtualenv or conda environment, you'll need to install that manually.


1 Answers

First you have to know the IP address of your server (ifconfig on posix and ipconfig on windows). Lets say the IP address is 10.10.10.10.

Then you can start the kernel on your server with:

ipython kernel --ip=* --IPKernelApp.connection_file=/tmp/kernel.json

When the kernel is started, get the content of the /tmp/kernel.json

$ cat /tmp/kernel.json
{
  "stdin_port": 59836,
  "ip": "*",
  "hb_port": 50806,
  "key": "11c2f53e-ad38-4d1d-b038-2f4bd04c4d49",
  "shell_port": 49904,
  "iopub_port": 55081
}

On your client create a /path/to/your/kernel.json file that has the same content, except that the ip address is the real ip address, and not the *:

{
  "stdin_port": 59836,
  "ip": "10.10.10.10",
  "hb_port": 50806,
  "key": "11c2f53e-ad38-4d1d-b038-2f4bd04c4d49",
  "shell_port": 49904,
  "iopub_port": 55081
}

After that you can start your qtconsole with:

ipython qtconsole --existing /path/to/your/kernel.json

You can connect as many qtconsoles as you want to the same kernel.

Note: Don't call the exit() function to exit your qtconsole, that will stop your kernel. Just click the close window button.

like image 100
Viktor Kerkez Avatar answered Sep 21 '22 01:09

Viktor Kerkez