【问题标题】:Load local data into IPython notebook server将本地数据加载到 IPython 笔记本服务器
【发布时间】:2015-07-10 05:17:16
【问题描述】:

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

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

【问题讨论】:

  • 您使用的是哪个IPython 版本?可能升级到jupyter
  • 我正在使用 jupyter。那么有没有办法上传数据呢?
  • 只需从您想要从中获取数据的目录(或其父目录)运行jupyter
  • 好吧,用户无权访问服务器目录。他们仅使用对 jupyter 的 Web 访问。要么笔记本需要能够访问客户端计算机上的目录,要么用户需要能够通过浏览器将他的数据上传到服务器。

标签: server ipython


【解决方案1】:

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

【讨论】:

  • 但这对我上传数据文件有什么帮助?
  • @MichaelHecht - 您可以将文件拖放到笔记本或使用click here 浏览到要上传的文件。请参阅更新的屏幕截图中的亮点。
  • 啊……好吧……我这几天不在办公室,不过我会尽快查的。提前谢谢你。
  • 嗯 - 它确实有效。也许这对我来说太容易蚂蚁太明显了?!在德国我们说:你看不到阿甘是因为前面的树太多了。不过,感谢您的热心帮助。
  • @Amit,如果你有大量文件要上传,比如 10k .txt 文件,你会怎么做?
【解决方案2】:

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

【讨论】:

  • 我遇到了问题,我收到 FileNotFoundError: [Errno 2] No such file or directory: 我的 jupyter notebook 正在远程服务器上运行,我想从我的笔记本电脑上传一个文件。 @volhv
【解决方案3】:

运行jupyter ipython notebook 后,点击new --> 转到terminal,然后简单地运行以下命令:

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

【讨论】:

    【解决方案4】:

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

    您可以这样做以绕过 25mb 限制

    【讨论】:

      猜你喜欢
      • 2013-05-27
      • 1970-01-01
      • 2014-09-11
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 2014-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多