注册 登录
新科学想法 返回首页

阿平的个人空间 https://www.xinkexue.com/?1 [收藏] [复制] [分享] [RSS]

日志

数据科学的一种Python工作模式:Spyder IDE 远程访问服务器 Jupyter qt console ... . ...

已有 2302 次阅读 2019-12-30 22:37 |个人分类:开发日志| spyder, python, qtconsole, jupyter, notebook, python, python, python, python, python

做数据科学分析很多时候代码在本地,而数据与运算要依赖在远程的服务器,这点在处理大数据时特别重要。
Jupyter notebook可通过ssh tunnel 的方法使这种远程计算的方法方便地在本地实现。
不过我相信还是有一部分用户不喜欢 Jupyter notebook(比如程序员),这里提供一个用Spyder IDE实现的远程qt console访问:

1. 在本地和远程通过conda安装 
spyder ,jupyter, jupyter-console, jupyter-qtconsole

2. 在本地机(localhost)与远程机(remote_server)查询 jupyter runtime目录
# jupyter --runtime-dir
比如本地:/Users/myuser/Library/Jupyter/runtime
比如远程:/home/myuser/.local/share/jupyter/runtime

3. 在远程服务器的工作目录下开启ipython服务
输入 ipython kernel,
会出现提示包含:
To connect another client to this kernel, use:
    --existing kernel-118573.json
其中的kernel-118573.json文件之后有用。

4. 将kernel-json文件从服务器复制到本地(bash 代码)
LOCAL=/Users/myuser/Library/Jupyter/runtime
REMOTE=/home/myuser/.local/share/jupyter/runtime
FILE=kernel-118573.json
scp username@remote_server:$REMOTE/$FILE $LOCAL/

5. (可选)假如不想整合spyder,而直接在本地用qtconsole
jupyter qtconsole --ssh=username@remote_server --ip=remote_ip --existing $LOCAL/$FILE

6. 在Spyder中调用qt console

在spyder IDE下的console面板 选择 "Connect to an existing kernel"


输入远程服务器的信息,其中“Connection file”要填写的就是/Users/myuser/Library/Jupyter/runtime/kernel-118573.json

需要通过SSH登陆服务器,Hostname填写服务器的IP地址或域名,Username填写登陆用户名,Password为对应的密码,也可用SSH key文件登陆。


登陆成功会看到以下console信息


现在我们用spyder  + qtconsole + scanpy 来做单细胞数据分析吧:)


鸡蛋

鲜花

握手

雷人

路过

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

Copyright;  © 新科学想法 2016-2017   浙公网安备 33010202000686号   ( 浙ICP备09035230号-1 )