问题
- I have a Windows machine where I start an IPython kernel (to do some stuff not possible on another machine).
- I have a Linux machine from which I would like to connect to the IPython kernel running on the Windows machine.
- I can SSH from the Linux machine to the Windows machine (using this solution: https://superuser.com/a/172299).
I have tried following: https://github.com/ipython/ipython/wiki/Cookbook:-Connecting-to-a-remote-kernel-via-ssh. Both the automatic and the manual solution gives the following:
"ERROR: Kernel did not respond"
Using the same solution, I can connect from my Linux machine to an IPython kernel running on a Linux server. Any solution to get this to work with Linux to Windows?
回答1:
I tried the manual way on https://github.com/ipython/ipython/wiki/Cookbook%3a-Connecting-to-a-remote-kernel-via-ssh once again and it worked. In detail:
windows-machine$ ipython kernel -f kernel-1234.json
linux-machine$ scp windows-machine:path/to/kernel-1234.json .
linux-machine$ cat kernel-1234.json
{
"stdin_port": 55534,
"ip": "127.0.0.1",
"control_port": 58391,
"hb_port": 60540,
"signature_scheme": "hmac-sha256",
"key": "fa461cf7-f078-4c22-909f-cfa7d2a30596",
"shell_port": 60159,
"transport": "tcp",
"iopub_port": 59207
}
linux-machine$ ssh -f -N -L 55534:127.0.0.1:55534
linux-machine$ ssh -f -N -L 58391:127.0.0.1:58391
linux-machine$ ssh -f -N -L 60540:127.0.0.1:60540
linux-machine$ ssh -f -N -L 60159:127.0.0.1:60159
linux-machine$ ssh -f -N -L 59207:127.0.0.1:59207
linux-machine$ ipython console --existing kernel-1234.json
回答2:
You don’t need SSH to connect to a remote ipython kernel, regardless of whether it’s a ipython kernel running on Windows or Linux or Mac. What you do need is to have the Ip of the remote kernel visible to the terminal from which you are trying to connect from. Here are the steps:
Find out the ip address of the
server(the machine on which the ipython kernel is running i.e. where you want the computation to happen) andclient(the machine from which you are trying to connect to):1.1. If you are on
Windows, open up the command prompt and do aipconfigto find out the ip addresses. If theWindowsserver has a direct Internet connection/lan connection, you should see a couple of ips like192.168.57.1and10.2.3.64and127.0.0.1.1.2. If you are on
linux, open up a terminal and typeifconfigorip addr show. You should again see a couple of ips like192.168.57.1and10.2.3.64and127.0.0.1.1.3. Test that atleast one of your
serverip addresses is visible from theclient: Ping yourserverfrom yourclient, using the commandping.pingwill work on either Windows or Linux terminals. If you are running the windows/Linux as a VM or is behind a firewall, it is very much possible that your client or server is not visible from the other side. You don’t have to ping the ip address127.0.0.1. This is a loop back address, and is only visible from the same machine where you got this ip address from. For example if you ping127.0.0.1from the Windows machine, it will ping the same Windows machine. If yourclientandserverinstances are running on the same machine, then its fine to use this address. However, if your client or server is running on a VM or a different machine altogher, then127.0.0.1wont work.Start the remote kernel:
2.1. Once you have figured out which ip address on the server is visible from the client, start a kernel on the machine using
ipython kernel. The ipython kernel will startup and show that `To connect another client to this kernel, use: --existing kernel-1234.json2.2. Locate the
kernel-1234.jsonfile on yourserverby importing (https://stackoverflow.com/a/35094772/4752883)In [1]: from jupyter_client import find_connection_file In [2]: find_connection_file() Out[2]: 'C:\\Users\\me\\AppData\\Roaming\\jupyter\\runtime\\kernel-1234.json'This will work either forLinuxorWindows.Start the remote client:
3.1. Once you locate the file, copy it over to your server machine using
scpin linux orpscporwinscpin windows SCP w/ ssh: copying a local file from windows to a remote server using scp3.2. Make sure that you are the same directory as the
kernel-1234.jsonfile.3.3. Open up the
kernel-1234.jsonfile using vim or your favorite text editor. You will notice a line saying"ip": "127.0.0.1". Change127.0.0.1theipaddress from your server that is visible from the client, that you found in step1.3and save thejsonfile.3.4. Start up the remote kernel using
jupyter console –existing=kernel-1234.json, while located in the same drive wherekernel-1234.jsonis located.
If you have followed the steps above, you should now be able to connect to the remote ipython kernel regardless of whether the ipython kernel is running on Windows/Linux/Mac.
来源:https://stackoverflow.com/questions/24004074/connecting-to-a-windows-ipython-kernel-from-linux