【问题标题】:How to run jupyter notebook slideshows in a cloud?如何在云中运行 jupyter notebook 幻灯片?
【发布时间】:2018-09-10 20:15:59
【问题描述】:

我在 google 计算引擎上有一个实例,我以这样的方式设置了我可以使用我的本地计算机浏览器在 jupyter 笔记本上工作。我通过使用端口 8888 输入外部 ip 连接到虚拟机,我准备好了。

现在我想将一个 jupyter notebook 转换成我想以某种方式访问​​的幻灯片。我尝试关注nbconvert documentation,并在我的虚拟机控制台中使用了以下命令:

jupyter nbconvert your_talk.ipynb --to slides --post serve

我的虚拟机控制台说:

[NbConvertApp] Converting notebook your_talk.ipynb to slides
[NbConvertApp] Writing 254651 bytes to your_talk.slides.html
[NbConvertApp] Redirecting reveal.js requests to https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.5.0
Serving your slides at http://127.0.0.1:8000/your_talk.slides.html
Use Control-C to stop this server
[NbConvertApp] WARNING | No web browser found: could not locate runnable browser.

我了解它试图在虚拟机网络浏览器上运行幻灯片。但是,关键是要从 VM 外部访问此幻灯片。因此问题:

问题。如何在我的 VM 上托管 jupyter notebook 幻灯片,以便我可以使用本地计算机远程访问它们?

附言。我有文件 your_talk.slides.html 可以访问,但它只是静态 html 文件。


读者注意:如果您阅读了这个问题并且认为我应该使用不同的标签,请随意更改它们。


记录到 Marcins 建议

RequestException                          Traceback (most recent call last)
<ipython-input-3-08768ed6fc86> in <module>()
      1 import datalab.storage as gcs
      2 slides = get_ipython().getoutput('jupyter nbconvert your_talk.ipynb --to slides --stdout')
----> 3 gcs.Bucket('myownbucket').item('slides.html').write_to("".join(slides[1:]),'text/html')

~/anaconda3/lib/python3.6/site-packages/datalab/storage/_item.py in write_to(self, content, content_type)
    222       self._api.object_upload(self._bucket, self._key, content, content_type)
    223     except Exception as e:
--> 224       raise e
    225 
    226 

~/anaconda3/lib/python3.6/site-packages/datalab/storage/_item.py in write_to(self, content, content_type)
    220     """
    221     try:
--> 222       self._api.object_upload(self._bucket, self._key, content, content_type)
    223     except Exception as e:
    224       raise e

~/anaconda3/lib/python3.6/site-packages/datalab/storage/_api.py in object_upload(self, bucket, key, content, content_type)
    161     url = Api._UPLOAD_ENDPOINT + (Api._OBJECT_PATH % (bucket, ''))
    162     return datalab.utils.Http.request(url, args=args, data=content, headers=headers,
--> 163                                       credentials=self._credentials, raw_response=True)
    164 
    165   def objects_copy(self, source_bucket, source_key, target_bucket, target_key):

~/anaconda3/lib/python3.6/site-packages/datalab/utils/_http.py in request(url, args, data, headers, method, credentials, raw_response, stats)
    153           return json.loads(str(content, encoding='UTF-8'))
    154       else:
--> 155         raise RequestException(response.status, content)
    156     except ValueError:
    157       raise Exception('Failed to process HTTP response.')

RequestException: HTTP request failed: Insufficient Permission

调用$ datalab create --verbosity=debug datalab-instance-name后的错误日志:

DEBUG: Running [gcloud.compute.zones.list] with arguments: [--format: "value(name)", --quiet: "True", --verbosity: 
"debug"]
INFO: Display format: "        table(name,
              region.basename(),
              status():label=STATUS,
              maintenanceWindows.next_maintenance():label=NEXT_MAINTENANCE,
              deprecated.deleted:label=TURNDOWN_DATE
        ) value(name)"
DEBUG: (gcloud.compute.zones.list) Some requests did not succeed:
 - Insufficient Permission
Traceback (most recent call last):
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 839, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 772, in Run
    display_info=self.ai.display_info).Display()
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/calliope/display.py", line 477, in Display
    self._printer.Print(self._resources)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/core/resource/resource_printer_base.py", line 256, in Print
    for resource in resources:
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/core/util/peek_iterable.py", line 206, in next
    return self.__next__()
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/core/util/peek_iterable.py", line 211, in __next__
    item = self._NextItem()
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/core/util/peek_iterable.py", line 183, in _NextItem
    return next(self._iterable)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/compute/lister.py", line 924, in __call__
    utils.RaiseException(errors, ListException)
  File "/usr/lib/google-cloud-sdk/lib/googlecloudsdk/api_lib/compute/utils.py", line 123, in RaiseException
    errors))
ListException: Some requests did not succeed:
 - Insufficient Permission
ERROR: (gcloud.compute.zones.list) Some requests did not succeed:
 - Insufficient Permission
A nested call to gcloud failed.
Command: ["gcloud","compute","--verbosity=debug","zones","--quiet","list","--format=value(name)"]
Return code: 1

【问题讨论】:

  • 你想访问 jupyter notebooks 还是你的一张幻灯片?
  • @mjsameri 我可以访问 jupyter 笔记本。我对幻灯片有疑问

标签: python google-cloud-platform jupyter-notebook slideshow


【解决方案1】:

您知道 Google Cloud DataLab 吗?这基本上是 GCP 上的 Jupyter 托管服务。无论如何,以下代码片段(从笔记本内部运行时,Python=3)将获取您的笔记本,将其转换为幻灯片并上传到 Cloud Storage。您可以公开从云存储服务您的苍蝇:

import datalab.storage as gcs
slides = !jupyter nbconvert <your_notebook>.ipynb --to slides --stdout
gcs.Bucket('<your_bucket_name>').item('slides.html').write_to("".join(slides[1:]),'text/html')

要使其公开,请在您的存储桶权限中添加具有“存储对象查看者”角色的“allUsers”成员。请注意,这将使您的存储桶在互联网上公开可用。

如果您不使用 DataLab,您可能需要将 datalab.storage 添加为 Python 环境的依赖项。

我认为在您的情况下,这比在 VM 上配置防火墙并将其暴露于入站流量要容易得多,也更安全。

【讨论】:

  • 你的方式看起来很吸引人,所以我试了一下。我关注了DataLab Quickstart。我已经完成了 3 个第一点和我在 VM 上完成的 4th one。但是,当我在虚拟机上调用“gcloud init”时,它会要求我选择一些帐户,但最终我没有权限。我还尝试创建一个新文件“upload_to_bucket.ipynb”,然后将带有个性化名称的代码粘贴到那里。我记录了权限存在问题的日志。 (我将它附加到我的帖子中)
  • 附言。我想直接从我的 MV 将幻灯片上传到存储桶,因此我在 VM 上进行了第四步,
  • 是的,您需要整理出您的权限。我将无能为力。这可能就像启用 API 一样简单。
  • 我在 DataLab 快速入门中启用了 API。但是,我想知道我是否应该在我的虚拟机上执行第四步。即按照教程在 VM 上安装和初始化 Cloud SDK。在运行您的代码之前,我是否必须在 VM 上调用 gcloud init
  • 您已经在 GCP 上自动为项目配置了虚拟机,无需运行 gcloud init。你需要这个来从 GCP 外部管理你的云,除非你有一个非常自定义的虚拟机,我不认为是这种情况。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-03
  • 1970-01-01
  • 1970-01-01
  • 2019-03-26
  • 2021-12-06
  • 2016-04-12
  • 1970-01-01
相关资源
最近更新 更多