Binder
能做什么?
Binder
提供代码以及执行它的硬件和软件的服务。
创建仓库
-
在
GitHub
创建仓库"my-first-binder"- 确定仓库是
public
- 不要忘记初始化
README
- 确定仓库是
-
通过Web界面创建一个名为hello.py的文件,添加内容
print(“ Hello from Binder!”)
并提交给master
分支
使用Binder
启动仓库
- 打开 https://mybinder.org
- 在"GitHub repo or URL" 输入框中,键入新建仓库地址:
https://github.com/wblong/my-first-binder.git
- 单击“Launch”按钮,等待环境创建成功后,浏览器会自动弹出
Jupyter Notebook
界面
运行 hello.py
- 在
Jupyter Notebook
右上角,单击"New" -> “Terminal” - 在新Tab页面的终端中键入
python hello.py
,并回车
终端会执行脚本,打印Hello from Binder!
添加依赖
- 代码仓库新建
requirements.txt
- 添加
numpy==1.14.5
- 提交代码
- 重新启动“Launch”,并查看" Build Logs"
检查环境
- 在
Jupyter Notebook
右上角,单击"New" -> “Python3” 打开notebook - 新建一个Cell,键入:
import numpy
print(numpy.__version__)
numpy.random.randn()
- 运行
共享
直接分享链接
https://mybinder.org/v2/gh/wblong/pvgeo-binder.git/master
共享数据
下载dropbox
链接的数据。
import urllib.request
link = 'https://dl.dropbox.com/s/gw5v3tiq68oge3l/Example-Extract-Topo.zip?dl=0'
f=urllib.request.urlopen(link)
with open("topo.vtk", "wb") as code:
code.write(f.read())
print("test")