通过双击 osx 打开 ipython notebook [英] Open an ipython notebook via double-click on osx

查看:17
本文介绍了通过双击 osx 打开 ipython notebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了几个 ipython 笔记本,我想在浏览器选项卡中打开它们,而无需导航到我下载它们的目录并运行 ipython notebook notebook_name.ipynb.

我意识到这可能意味着我很懒,但这对我来说似乎是一个常见的用例.我是否遗漏了一些明显的东西?

解决方案

我找到了使用 Automator 的好方法(2017 年 10 月;信息来自

  • 从列表中添加Run Shell Script 拖放;可能需要这些设置 Shell:/bin/bashPass input: as arguments
  • 插入下面的代码;如有必要,调整 jupyter 的路径
  • 代码

    #!/bin/sh变量="'$1'";the_script='tell 应用程序终端"做脚本/usr/local/bin/jupyter notebook"osascript -e "${the_script}${variable}"";

    1. 将脚本保存应用程序 (!)
    2. 尝试打开一个 .ipynb 文件并将默认应用程序更改为这个新创建的应用程序.


    备注

    1. 这将打开一个终端并运行 jupyter notebook 命令,这样您就可以从那里中断和停止笔记本服务器.另请注意,您不能像 Automator 那样测试应用程序,但需要添加 Get Specified Finder Items 并在那里插入一些测试笔记本(仅用于测试目的).

    正如评论中所指出的,还有两个注意事项:

    1. 为避免使用笔记本向浏览器历史发送垃圾邮件,您可以在隐身/私密模式下启动笔记本:在隐身窗口中运行 jupyter notebook

    2. 如果您想在一台服务器上运行笔记本并且不介意额外的工具,Sachit Nagpal 已经指出(谢谢),您还可以使用 nbopen.要使用此工作流程,只需将 "/usr/local/bin/jupyter notebook ' 替换为 "nbopen '.任何其他工具都应该类似.

    I've downloaded a couple of ipython notebooks, and I'd like to open them in browser tabs without navigating to the directory I've downloaded them to and running ipython notebook notebook_name.ipynb.

    I realize this probably means I'm lazy, but it seems like a common use case to me. Am I missing something obvious?

    解决方案

    I have found a nice way using Automator (Oct. 2017; with information from here):

    1. open Automator and create a new Application
    2. to add Run Shell Script drag and drop it from the list; might need these settings Shell: /bin/bash and Pass input: as arguments
    3. insert the code below; if necessary adjust the path to jupyter

    Code

    #!/bin/sh
    variable="'$1'"
    the_script='tell application "terminal" to do script "/usr/local/bin/jupyter notebook '
    osascript -e "${the_script}${variable}""
    

    1. save the script as an application (!)
    2. try to open a .ipynb file and change the default app to this newly created one.


    notes

    1. This will open a terminal and run the jupyter notebook command, such that you can interrupt and stop the notebook-server from there. Also note that you cannot test the app like that in Automator, but need to add the Get Specified Finder Items and insert some test notebook there (just for testing purposes).

    As pointed out in the comments, there are two more notes:

    1. To avoid spamming your browser history with notebooks, you can start your notebooks in incognito/private mode: Run jupyter notebook in incognito window

    2. If you want to run notebooks in one server and don't mind an extra tool, Sachit Nagpal has pointed out (thank you), that one could also use nbopen. To use this workflow just replace "/usr/local/bin/jupyter notebook ' with "nbopen '. Any other tool should work alike.

    这篇关于通过双击 osx 打开 ipython notebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆