简体   繁体   English

IPython笔记本之间的链接

[英]Links between IPython notebooks

Is it possible to link one IPython notebook to another with a hyperlink in a Markdown cell? 是否可以通过Markdown单元格中的超链接将一个IPython笔记本链接到另一个? If I try 如果我试试

Link to [Notebook 2](files/notebook2.ipynb)

or 要么

Link to <a href="files/notebook2.ipynb">Notebook 2</a>

A new tab is opened with raw unformatted contents of the ipynb file. 将打开一个新选项卡,其中包含ipynb文件的原始未格式化内容。 Is there a way to get IPython to open another notebook for use in a new tab via a hyperlink? 有没有办法让IPython通过超链接打开另一个笔记本用于新标签?

从IPython 2开始,您可以使用您首次尝试的语法:

Link to [Notebook 2](notebook2.ipynb)

It is now possible to do this with Ipython 1.0+ at least. 现在至少可以使用Ipython 1.0+来做到这一点。

Just do: localhost:8888/My Notebook.ipynb 只需:localhost:8888 / My Notebook.ipynb

Here is the documentation for this feature. 以下是此功能的文档。 https://github.com/ipython/ipython/pull/3058 https://github.com/ipython/ipython/pull/3058

From http://python.6.n6.nabble.com/where-is-the-code-to-generate-IPython-Notebook-URL-for-a-new-ipynb-file-td4996991.html : 来自http://python.6.n6.nabble.com/where-is-the-code-to-generate-IPython-Notebook-URL-for-a-new-ipynb-file-td4996991.html

You can access a json version of all the notebooks from url: $host/notebooks 您可以从url:$ host / notebooks访问所有笔记本的json版本

Here is a snippet that worked for me: 这是一个适合我的片段:

    import urllib2
    import json
    data = urllib2.urlopen("http://127.0.0.1:8888/notebooks")
    json_data=data.read()
    list_o_dicts=json.loads(json_data)
    for d in list_o_dicts:
        if d['name'] == 'test':
            print d['notebook_id']

Modify this according to your need. 根据您的需要进行修改。

** on further reading, I just realized OP was also seeking new notebook creation, keeping my answer anyway as way to work with linking existing notebooks. **在进一步阅读时,我刚刚意识到OP也在寻求新的笔记本创作,无论如何都要保留我的答案作为连接现有笔记本的方法。

One way to try for OP's goal is to run a script which will create a new notebook.ipynb file into the ipython folder where ipython notebook was started from. 尝试OP的目标的一种方法是运行一个脚本,该脚本将在ipython笔记本启动的ipython文件夹中创建一个新的notebook.ipynb文件。 That .ipynb file can be templated from a new ipython notebook created from dashboard, with the name and id of the notebook replaced with whatever you are trying to link from your existing notebook. 该.ipynb文件可以通过从仪表板创建的新ipython笔记本进行模板化,其中笔记本的名称和ID将替换为您尝试从现有笔记本链接的任何内容。 I have not tried this, but should work since dropping a .ipynb extension file into ipython folder does show it up in the dashboard. 我没有尝试过这个,但是应该工作,因为将.ipynb扩展文件放到ipython文件夹中确实会在仪表板中显示它。

In addition to akim's suggestion - you can link to any (py or ipynb) file using a relative link, starting with "edit", and and then from the directory where you started the server. 除了akim的建议 - 您可以使用相对链接链接到任何(py或ipynb)文件,从“编辑”开始,然后从启动服务器的目录开始。

Eg in a markdown cell, if I want to reference a file whose relative location (relative to my git repo, which is also where I launched the notebook server) is "./path/to/source.py", I'd add: 例如在markdown单元格中,如果我想引用一个文件,其相对位置(相对于我的git repo,也就是我启动笔记本服务器的地方)是“./path/to/source.py”,我会添加:

[link to source](/edit/path/to/source.py)

Unfortunately, this is not practically possible. 不幸的是,这实际上是不可能的。 The link would need to be to the notebook ID (eg /a1e2a88f-3b91-4a4e-8ca1-d4fd7240f750 for the one I'm working on right now). 链接需要是笔记本ID(例如/ a1e2a88f-3b91-4a4e-8ca1-d4fd7240f750 ,我正在处理的那个)。 This is an UUID created at startup by the IPython server. 这是由IPython服务器在启动时创建的UUID。 So you can copy the link from IPython Dashboard, but it will be valid only until you restart. 因此,您可以从IPython仪表板复制链接,但只有在重新启动后才会生效。

Remember that if your file name has spaces you will need to replace those with %20 请记住,如果您的文件名包含空格,则需要将其替换为%20

eg: 例如:

[Numpy](Numpy%20For%20Python.ipynb)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM