将本地数据加载到 IPython 笔记本服务器
Load local data into IPython notebook server
我确实为其他人(在我公司部门)设置了一个 ipython 服务器,以便有机会与 python 一起学习和工作。
现在我想知道人们如何将自己的本地数据加载到远程服务器上的 ipython 笔记本会话中。有什么办法吗?
由于您安装了 jupyter
,所有用户都应该在 jupyter
启动目录及其子目录中看到 files/folders。 jupyter
笔记本上的 new
按钮可用于创建新的 file/folder 甚至终端。可以使用拖放或下面突出显示的 click here
功能上传文件。
使用 python 实现此目的的另一种方法:
def jupyter_upload(token, filePath, resourceDstPath, jupyterUrl='http://localhost:8888'):
"""
Uploads File to Jupyter Notebook Server
----------------------------------------
:param token:
The authorization token issued by Jupyter for authentification
(enabled by default as of version 4.3.0)
:param filePath:
The file path to the local content to be uploaded
:param resourceDstPath:
The path where resource should be placed.
The destination directory must exist.
:param jupyterUrl:
The url to the jupyter server. Default value is typical localhost installation.
:return: server response
"""
import os
import base64
import urllib
import json
import requests
dstPath = urllib.quote(resourceDstPath)
dstUrl = '%s/api/contents/%s' % (jupyterUrl, dstPath)
fileName = filePath[1 + filePath.rfind(os.sep):]
headers = {}
headers['Authorization'] = 'token '+token
with open(filePath, 'r') as myfile:
data=myfile.read()
b64data=base64.encodestring(data)
body = json.dumps({
'content':b64data,
'name': fileName,
'path': resourceDstPath,
'format': 'base64',
'type':'file'
})
return requests.put(dstUrl, data=body, headers=headers, verify=True)
如果是文本文件,创建一个空文件,编辑它然后copy/paste内容..
您可以这样做来绕过 25mb 的限制
一旦你 运行 jupyter
ipython notebook,点击 new --> 转到 terminal
然后简单地运行 以下命令:
您可以在此处传递您的文件 url 并将您的文件上传到服务器上,然后就可以开始了。否则直接拖动文件或从 upload
按钮上传文件。
我确实为其他人(在我公司部门)设置了一个 ipython 服务器,以便有机会与 python 一起学习和工作。
现在我想知道人们如何将自己的本地数据加载到远程服务器上的 ipython 笔记本会话中。有什么办法吗?
由于您安装了 jupyter
,所有用户都应该在 jupyter
启动目录及其子目录中看到 files/folders。 jupyter
笔记本上的 new
按钮可用于创建新的 file/folder 甚至终端。可以使用拖放或下面突出显示的 click here
功能上传文件。
使用 python 实现此目的的另一种方法:
def jupyter_upload(token, filePath, resourceDstPath, jupyterUrl='http://localhost:8888'):
"""
Uploads File to Jupyter Notebook Server
----------------------------------------
:param token:
The authorization token issued by Jupyter for authentification
(enabled by default as of version 4.3.0)
:param filePath:
The file path to the local content to be uploaded
:param resourceDstPath:
The path where resource should be placed.
The destination directory must exist.
:param jupyterUrl:
The url to the jupyter server. Default value is typical localhost installation.
:return: server response
"""
import os
import base64
import urllib
import json
import requests
dstPath = urllib.quote(resourceDstPath)
dstUrl = '%s/api/contents/%s' % (jupyterUrl, dstPath)
fileName = filePath[1 + filePath.rfind(os.sep):]
headers = {}
headers['Authorization'] = 'token '+token
with open(filePath, 'r') as myfile:
data=myfile.read()
b64data=base64.encodestring(data)
body = json.dumps({
'content':b64data,
'name': fileName,
'path': resourceDstPath,
'format': 'base64',
'type':'file'
})
return requests.put(dstUrl, data=body, headers=headers, verify=True)
如果是文本文件,创建一个空文件,编辑它然后copy/paste内容..
您可以这样做来绕过 25mb 的限制
一旦你 运行 jupyter
ipython notebook,点击 new --> 转到 terminal
然后简单地运行 以下命令:
您可以在此处传递您的文件 url 并将您的文件上传到服务器上,然后就可以开始了。否则直接拖动文件或从 upload
按钮上传文件。