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

Mic*_*cht 8 ipython server

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

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

Ami*_*mit 9

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

在此输入图像描述

  • 嗯 - 确实有效.也许这太容易了,蚂蚁对我来说太明显了?!在德国,我们说:你没有看到福雷斯特,因为前面有太多的树木.不过,谢谢你的帮助. (3认同)

vol*_*lhv 8

使用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)
Run Code Online (Sandbox Code Playgroud)