Skip to content Skip to sidebar Skip to footer

Remote Jupyter Kernel - Different Virtual Environment?

I use the package remote_ikernel to automatically connect to an azure VM from an azure VM. The two systems are identical, that is, they have the same python environments. I start

Solution 1:

The kernel_cmd is what is run after making the remote connection, so to get the py36 version of ipython on the remote machine, your kernel.json should look more like:


{
    "argv": [
        "/anaconda/envs/py35/bin/python",
        "-m",
        "remote_ikernel",
        "--interface",
        "ssh",
        "--host",
        "{username}@{ip}",
        "--kernel_cmd",
        "/anaconda/envs/py36/bin/ipython kernel -f {host_connection_file}",
        "{connection_file}"
    ],
    "display_name": "SSH {username}@{kernel_name}",
    "remote_ikernel_argv": [
        "/anaconda/envs/py35/bin/remote_ikernel",
        "manage",
        "--add",
        "--kernel_cmd=/anaconda/envs/py36/bin/ipython kernel -f {connection_file}",
        "--name=Remote VM",
        "--interface=ssh",
        "--host={username}@{ip}"
    ]
}

This should be the same as if you invoke remote_ikernel with the commandline:

remote_ikernel manage --add --kernel_cmd="/anaconda/envs/py36/bin/ipython kernel -f {connection_file}" --name="Remote VM" --interface=ssh --host={username}@{ip}

Solution 2:

Not sure if it's still relevant but just in case: Use the --remote-precmd option when adding your kernel. According to the docs:

Command to execute on the remote host before launching the kernel, but after changing to the working directory.

You can use this option to activate your needed env:

--remote-precmd=source %PathToVenv%/Scripts/activate

I'm using it and it works with remote_ikernel v0.4.6 and my remote is Windows 10.

For Windows, the command would be something like this:

--remote-precmd=%PathToVenv%\\Scripts\\activate.bat

Post a Comment for "Remote Jupyter Kernel - Different Virtual Environment?"