我在谷歌计算引擎上有一个实例,我设置的方式是我可以使用我的本地计算机浏览器处理jupyter笔记本 . 我通过输入端口8888的外部IP连接到VM,我准备好了 .
现在我想把一个jupyter笔记本变成我想以某种方式访问的幻灯片 . 我试着关注nbconvert documentation并且在我的VMs控制台中使用了以下命令:
jupyter nbconvert your_talk.ipynb --to slides --post serve
我的VM控制台说:
[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.
我知道它试图在VMs Web浏览器上运行幻灯片 . 但是,重点是从VM外部访问此幻灯片 . 因此问题:
Question. 如何在我的VM上托管jupyter笔记本幻灯片,以便我可以使用本地计算机远程访问它们?
PS . 我有文件 your_talk.slides.html
我可以访问,但它只是静态的html文件 .
读者注意:如果您阅读此问题而您认为我应该使用不同的标签,请随时更改它们 .
Logs to Marcins suggestion
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
1 回答
您是否了解Google Cloud DataLab?这基本上是GCP上的Jupyter托管服务 . 无论如何,以下代码snipplet(当从笔记本内部运行时,Python = 3)将占用您的笔记本,将其转换为幻灯片并上传到 Cloud 存储 . 您可以公开地从 Cloud 存储中提供苍蝇:
要将其公开,在您的存储桶权限中,添加“allUsers”成员以及“存储对象查看器”角色 . 请注意,这将使您的存储桶在互联网上公开 .
如果您不使用DataLab,则可能需要将
datalab.storage
添加为Python env的依赖项 .我认为在您的情况下更容易,并且比在VM上配置防火墙并将其暴露给入站流量更安全 .