将本地数据加载到IPython笔记本服务器中

时间:2015-04-30 13:18:19

标签: server ipython

我为其他人(在我的公司部门)设置了一个ipython服务器,以便有机会学习和使用python。

现在我想知道人们如何将自己的本地数据加载到远程服务器上的ipython笔记本会话中。有没有办法做到这一点?

4 个答案:

答案 0 :(得分:8)

由于您安装了jupyter,所有用户都应该看到jupyter启动目录及其子目录中的文件/文件夹。 new笔记本上的jupyter按钮可用于创建新文件/文件夹甚至终端。可以使用拖放或下面突出显示的click here功能上传文件。

enter image description here

答案 1 :(得分:6)

使用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)

答案 2 :(得分:0)

如果是文本文件,请创建一个空文件,编辑它然后复制/粘贴内容..

您可以这样做以绕过25mb约束

答案 3 :(得分:0)

运行jupyter ipython笔记本后,点击 - >转到terminal,然后只需运行以下命令:

You can pass your files **url** here and get your file uploaded on the server and you are ready to go. Otherwise directly drag a file or upload the file from the <code>upload</code> button.

您可以在此处传递网址文件并将文件上传到服务器上,然后您就可以开始了。否则,直接拖动文件或从upload按钮上传文件。