远程Jupyter内核-不同的虚拟环境? [英] Remote jupyter kernel - different virtual environment?

查看:240
本文介绍了远程Jupyter内核-不同的虚拟环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用软件包remote_ikernel从azure VM自动连接到azure VM.这两个系统是相同的,也就是说,它们具有相同的python环境.

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.

我使用

ssh -oStrictHostKeyChecking=no {username}@{ip} sudo /anaconda/envs/py36/bin/ipython kernel

然后通过在下面的脚本中填充参数来更新我的本地kernel.json.

And then update my local kernel.json by filling the parameters in the script below.

        {{
    "argv": [
        "/anaconda/envs/py35/bin/python",
        "-m",
        "remote_ikernel",
        "--interface",
        "ssh",
        "--host",
        "{username}@{ip}",
        "--kernel_cmd",
        "/anaconda/envs/{remote_python}/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/{remote_python}/bin/ipython kernel -f {{connection_file}}",
        "--name=Remote VM",
        "--interface=ssh",
        "--host={username}@{ip}"
    ]
}}

首次尝试 但是,我们不想使用远程/anaconda/envs/py35/bin/python,而是使用它的py36兄弟.我希望通过在第一个命令中对其进行调整来解决该问题,但这并不能解决问题.它也无助于更改kernel.json中的任何py35.我们如何实现这一目标?

First attempt However, we don't want to use the remote /anaconda/envs/py35/bin/python but its py36 brother. I hoped to solve that by adjusting it in the 1st command, but that doesn't solve it. It also didn't help to change any of the py35 in the kernel.json. How can we achieve that?

第二次尝试(编辑) 我修改了kernel.json以包含指向py36环境的指针.请参阅上面的更新版本.下面的日志看起来不错,但是import sys; sys.executable仍显示py35版本.

Second attempt (edit) I adapted the kernel.json to include the pointer to the py36 environment. See the updated version above. The log below looks fine, but import sys; sys.executable still shows the py35 version.

[I 11:54:57.549 remote_ikernel] Launching kernel over SSH.
[I 11:54:57.549 remote_ikernel] Login command: 'ssh -o StrictHostKeyChecking=no  username@ip'.
[I 11:54:57.889 remote_ikernel] Established connection; starting kernel.
[I 11:54:57.889 remote_ikernel] Current working directory /data/projects/...
[I 11:54:58.040 remote_ikernel] Running kernel command: '/anaconda/envs/py36/bin/ipython kernel -f ./rik_kernel-40d44e0d-4dac-4939-b018-74f4c82b6855.json'.
[I 11:54:59.357 NotebookApp] Adapting to protocol v5.1 for kernel 40d44e0d-4dac-4939-b018-74f4c82b6855
[I 11:54:59.358 NotebookApp] Restoring connection for 40d44e0d-4dac-4939-b018-74f4c82b6855:d877b8cff59245bf9ca5811d9310ee7f
[I 11:54:59.358 NotebookApp] Replaying 7 buffered messages
[I 11:55:28.382 remote_ikernel] Setting up tunnels on ports: 57033, 45674, 57305, 38105, 56085.

显示的远程内核文件

 {
  "shell_port": 45674,
  "iopub_port": 57305,
  "stdin_port": 38105,
  "control_port": 56085,
  "hb_port": 57033,
  "ip": "127.0.0.1",
  "key": "9e336436-...",
  "transport": "tcp",
  "signature_scheme": "hmac-sha256",
  "kernel_name": ""
}

推荐答案

不确定是否仍然有用,以防万一:
添加内核时,请使用--remote-precmd选项.
根据文档:

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

我正在使用它,它可与remote_ikernel v0.4.6一起使用,而我的遥控器是Windows10.

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

对于Windows,该命令应如下所示:

For Windows, the command would be something like this:

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

这篇关于远程Jupyter内核-不同的虚拟环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆