我使用包remote_ikernel
自动从天蓝色虚拟机连接到天蓝色虚拟机。两个系统是相同的,即具有相同的python环境。
我使用启动远程内核
ssh -oStrictHostKeyChecking=no {username}@{ip} sudo /anaconda/envs/py36/bin/ipython kernel
然后通过填写下面脚本中的参数来更新我的本地 kernel.json
。
{{
"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 。我们怎样才能做到这一点?
第二次尝试(编辑)
我调整了 kernel.json
以包含指向 py36
环境的指针。请参阅上面的更新版本。下面的日志看起来不错,但是 import sys; sys.executable
仍然显示 py35
版本。
[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": ""
}
最佳答案
kernel_cmd
是在建立远程连接后运行的,因此要在远程计算机上获取 py36 版本的 ipython,您的 kernel.json
应该看起来更像:
{
"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}"
]
}
这应该与使用命令行调用 remote_ikernel
相同:
remote_ikernel manage --add --kernel_cmd="/anaconda/envs/py36/bin/ipython kernel -f {connection_file}" --name="Remote VM" --interface=ssh --host={username}@{ip}
关于python - 远程 jupyter 内核 - 不同的虚拟环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55730569/