我试过的:
启动 Google Cloud shell
sudo pip install jupyter
jupyter notebook --generate-config
将以下内容添加到~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip = 'localhost'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8080
c.NotebookApp.allow_origin = '*'
c.ConnectionFileMixin.control_port = 8081
c.ConnectionFileMixin.hb_port = 8082
c.ConnectionFileMixin.iopub_port = 8083
c.ConnectionFileMixin.shell_port = 8084
c.ConnectionFileMixin.stdin_port = 0
跑
jupyter notebook --no-browser --debug
转到网络预览,主页加载得很好,但是当我加载一个新的笔记本 .ipynb 时,我得到:
无法建立到笔记本服务器的连接。笔记本电脑将继续尝试重新连接。检查您的网络连接或笔记本服务器配置。
开发者控制台中的错误:
main.min.js:22712 WebSocket 连接到“wss://8080-dot-2103947-dot-devshell.appspot.com/api/kernels/05832e24-2cd6-421c-aa55-16c58eceab94/channels?session_id=83EE7CD1C17942BE827623E5DFF08240”失败:WebSocket 握手期间出错:意外响应代码:400
但在 Google Cloud Shell 中,没有 400 错误:
[D 19:36:27.820 NotebookApp] Searching [u'/home/jie', '/home/jie/.jupyter', '/usr/etc/jupyter', '/usr/local/etc/jupyter', '/etc/jupyter'] for config files
[D 19:36:27.821 NotebookApp] Looking for jupyter_config in /etc/jupyter
[D 19:36:27.822 NotebookApp] Looking for jupyter_config in /usr/local/etc/jupyter
[D 19:36:27.861 NotebookApp] Looking for jupyter_config in /usr/etc/jupyter
[D 19:36:27.862 NotebookApp] Looking for jupyter_config in /home/jie/.jupyter
[D 19:36:27.863 NotebookApp] Looking for jupyter_config in /home/jie
[D 19:36:27.865 NotebookApp] Looking for jupyter_notebook_config in /etc/jupyter
[D 19:36:27.866 NotebookApp] Looking for jupyter_notebook_config in /usr/local/etc/jupyter
[D 19:36:27.866 NotebookApp] Looking for jupyter_notebook_config in /usr/etc/jupyter
[D 19:36:27.867 NotebookApp] Looking for jupyter_notebook_config in /home/jie/.jupyter
[D 19:36:27.868 NotebookApp] Loaded config file: /home/jie/.jupyter/jupyter_notebook_config.py
[D 19:36:27.869 NotebookApp] Looking for jupyter_notebook_config in /home/jie
[I 19:36:29.267 NotebookApp] Serving notebooks from local directory: /home/jie
[I 19:36:29.268 NotebookApp] 0 active kernels
[I 19:36:29.268 NotebookApp] The Jupyter Notebook is running at: http://localhost:8080/
[I 19:36:29.268 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 19:36:36.858 NotebookApp] 302 GET /?authuser=0 (127.0.0.1) 1.20ms
[D 19:36:37.525 NotebookApp] Using contents: services/contents
[D 19:36:37.562 NotebookApp] 200 GET /tree (::1) 38.02ms
[D 19:36:38.268 NotebookApp] 200 GET /custom/custom.css (127.0.0.1) 1.60ms
[D 19:36:39.180 NotebookApp] 200 GET /static/services/contents.js?v=20160919193627 (::1) 1.45ms
[D 19:36:39.184 NotebookApp] 200 GET /custom/custom.js?v=20160919193627 (127.0.0.1) 1.47ms
[D 19:36:39.906 NotebookApp] 200 GET /api/config/tree?_=1474285000896 (::1) 3.61ms
[D 19:36:39.910 NotebookApp] 200 GET /api/terminals?_=1474285000900 (127.0.0.1) 1.15ms
[D 19:36:39.915 NotebookApp] 200 GET /api/config/common?_=1474285000897 (::1) 3.59ms
[D 19:36:39.918 NotebookApp] 200 GET /api/terminals?_=1474285000898 (::1) 1.07ms
[D 19:36:39.940 NotebookApp] 200 GET /api/sessions?_=1474285000899 (127.0.0.1) 20.56ms
[D 19:36:39.945 NotebookApp] Native kernel (python2) available from /usr/local/lib/python2.7/dist-packages/ipykernel/resources
[D 19:36:39.945 NotebookApp] Native kernel (python2) available from /usr/local/lib/python2.7/dist-packages/ipykernel/resources
[D 19:36:39.947 NotebookApp] 304 GET /api/kernelspecs (127.0.0.1) 5.75ms
[D 19:36:40.593 NotebookApp] 200 GET /api/contents?type=directory&_=1474285000901 (::1) 4.76ms
[D 19:37:40.160 NotebookApp] 200 GET /api/sessions?_=1474285000902 (127.0.0.1) 1.15ms
[D 19:37:40.162 NotebookApp] 200 GET /api/terminals?_=1474285000903 (::1) 0.65ms
[D 19:37:41.392 NotebookApp] 200 GET /api/contents?type=directory&_=1474285000904 (127.0.0.1) 3.10ms
[D 19:38:40.143 NotebookApp] 200 GET /api/sessions?_=1474285000905 (::1) 1.34ms
[D 19:38:40.209 NotebookApp] 200 GET /api/terminals?_=1474285000906 (127.0.0.1) 1.07ms
[D 19:38:40.766 NotebookApp] 200 GET /api/contents?type=directory&_=1474285000907 (::1) 3.33ms
[D 19:39:14.165 NotebookApp] 200 GET /api/sessions?_=1474285000908 (127.0.0.1) 1.05ms
[D 19:39:14.192 NotebookApp] 200 GET /api/terminals?_=1474285000909 (::1) 0.96ms
[D 19:39:14.761 NotebookApp] 200 GET /api/contents?type=directory&_=1474285000910 (127.0.0.1) 3.22ms
[D 19:40:40.338 NotebookApp] 200 GET /api/sessions?_=1474285000911 (::1) 1.40ms
[D 19:40:40.363 NotebookApp] 200 GET /api/terminals?_=1474285000912 (127.0.0.1) 0.94ms
[D 19:40:40.936 NotebookApp] 200 GET /api/contents?type=directory&_=1474285000913 (::1) 3.39ms
[D 19:42:13.646 NotebookApp] 200 GET /api/sessions?_=1474285000914 (127.0.0.1) 1.41ms
[D 19:42:13.649 NotebookApp] 200 GET /api/terminals?_=1474285000915 (::1) 0.77ms
[D 19:42:15.178 NotebookApp] 200 GET /api/contents?type=directory&_=1474285000916 (127.0.0.1) 5.44ms
[I 19:42:17.736 NotebookApp] Creating new notebook in
[D 19:42:17.738 NotebookApp] Saving /home/jie/Untitled1.ipynb
[D 19:42:17.851 NotebookApp] 201 POST /api/contents (::1) 117.08ms
[D 19:42:18.462 NotebookApp] Using contents: services/contents
[D 19:42:18.494 NotebookApp] 200 GET /notebooks/Untitled1.ipynb?kernel_name=python2 (127.0.0.1) 32.79ms
[D 19:42:19.275 NotebookApp] 304 GET /custom/custom.css (::1) 1.28ms
[D 19:42:19.296 NotebookApp] 200 GET /static/components/MathJax/MathJax.js?config=TeX-AMS_HTML-full,Safe&delayStartupUntil=configured (127.0.0.1) 2.40ms
[D 19:42:20.407 NotebookApp] 200 GET /static/components/MathJax/config/TeX-AMS_HTML-full.js?rev=2.6.0 (::1) 2.29ms
[D 19:42:20.609 NotebookApp] 304 GET /custom/custom.js?v=20160919193627 (127.0.0.1) 1.11ms
[D 19:42:21.246 NotebookApp] 200 GET /api/config/common?_=1474285342417 (::1) 3.12ms
[D 19:42:21.300 NotebookApp] 200 GET /api/contents/Untitled1.ipynb?type=notebook&_=1474285342418 (127.0.0.1) 44.64ms
[D 19:42:21.302 NotebookApp] Native kernel (python2) available from /usr/local/lib/python2.7/dist-packages/ipykernel/resources
[D 19:42:21.303 NotebookApp] Native kernel (python2) available from /usr/local/lib/python2.7/dist-packages/ipykernel/resources
[D 19:42:21.305 NotebookApp] 304 GET /api/kernelspecs (127.0.0.1) 2.81ms
[D 19:42:21.309 NotebookApp] 200 GET /api/config/notebook?_=1474285342416 (::1) 2.74ms
[D 19:42:22.147 NotebookApp] Native kernel (python2) available from /usr/local/lib/python2.7/dist-packages/ipykernel/resources
[D 19:42:22.149 NotebookApp] Starting kernel: ['/usr/bin/python', '-m', 'ipykernel', '-f', u'/home/jie/.local/share/jupyter/runtime/kernel-05832e24-2cd6-421c-aa55-16c58eceab94.json']
[D 19:36:37.562 NotebookApp] 200 GET /tree (::1) 38.02ms
[D 19:42:22.153 NotebookApp] Connecting to: tcp://127.0.0.1:8081
[I 19:42:22.155 NotebookApp] Kernel started: 05832e24-2cd6-421c-aa55-16c58eceab94
[D 19:42:22.155 NotebookApp] Kernel args: {'kernel_name': u'python2', 'cwd': u'/home/jie'}
[D 19:42:22.161 NotebookApp] 201 POST /api/sessions (::1) 87.33ms
[D 19:42:22.165 NotebookApp] 200 GET /api/contents/Untitled1.ipynb/checkpoints?_=1474285342419 (127.0.0.1) 1.60ms
[D 19:42:22.276 NotebookApp] Using contents: services/contents
[W 19:42:22.293 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js?v=20160919193627 (::1) 19.36ms referer=https://8080-dot-2103947-dot-devshell.appspot
.com/notebooks/Untitled1.ipynb?kernel_name=python2
[D 19:42:22.350 NotebookApp] Native kernel (python2) available from /usr/local/lib/python2.7/dist-packages/ipykernel/resources
[D 19:42:22.351 NotebookApp] Serving kernel resource from: /usr/local/lib/python2.7/dist-packages/ipykernel/resources
[D 19:42:22.356 NotebookApp] 304 GET /kernelspecs/python2/logo-64x64.png (127.0.0.1) 7.08ms
[D 19:42:22.401 NotebookApp] 200 GET /static/style/style.min.css.map (::1) 1.83ms
[D 19:42:22.549 NotebookApp] 200 GET /static/components/MathJax/config/Safe.js?rev=2.6.0 (127.0.0.1) 2.08ms
[D 19:42:23.217 NotebookApp] 200 GET /static/components/MathJax/jax/output/HTML-CSS/fonts/STIX-Web/fontdata.js?rev=2.6.0 (::1) 1.41ms
[D 19:42:23.240 NotebookApp] 200 GET /static/components/MathJax/extensions/Safe.js?rev=2.6.0 (127.0.0.1) 1.25ms
[D 19:42:52.652 NotebookApp] 200 GET /api/sessions?_=1474285000917 (::1) 3.00ms
[D 19:42:52.654 NotebookApp] 200 GET /api/terminals?_=1474285000918 (127.0.0.1) 0.65ms
[D 19:42:53.314 NotebookApp] 200 GET /api/contents?type=directory&_=1474285000919 (::1) 4.03ms
[D 19:44:22.156 NotebookApp] 200 GET /api/contents/Untitled1.ipynb?content=0&_=1474285342420 (127.0.0.1) 1.36ms
[I 19:44:22.762 NotebookApp] Saving file at /Untitled1.ipynb
[D 19:44:22.763 NotebookApp] Saving /home/jie/Untitled1.ipynb
[D 19:44:22.826 NotebookApp] 200 PUT /api/contents/Untitled1.ipynb (::1) 64.32ms
所以这让我认为 Web 套接字请求没有到达内核,它们被 Google Cloud Shell 阻止了。Google App Engine 没有免费提供 Socket API,这就是我不能让它工作的原因吗?