用python文件启动ipython notebook [英] start ipython notebook with python file

查看:140
本文介绍了用python文件启动ipython notebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对python / ipython不是很熟悉,但是有人问我是否可以用特定的python文件启动ipython笔记本。然后它可以用于调试。
另一个软件然后会在temp文件夹中创建一个.py文件,并用这个文件调用一个ipython笔记本。
是否有可能或有意义?

I am not very familiar with python/ipython but somebody was asking me whether it is possible to start an ipython notebook with a specific python file. It then could be used for debugging. another software then would create a .py-file in the temp folder and would call an ipython notebook with this file. Is it possible or does it make sense at all?

推荐答案

如果您正在谈论推出iPython笔记本电脑服务器通过Python,我使用:

If you're talking about launching an iPython notebook server via Python, I use this:

#!/usr/bin/env python
from IPython.terminal.ipapp import launch_new_instance
from IPython.lib import passwd
from socket import gethostname
import warnings
warnings.filterwarnings("ignore", module = "zmq.*")
sys.argv.append("notebook")
sys.argv.append("--IPKernelApp.pylab='inline'")
sys.argv.append("--NotebookApp.ip=" + gethostname())
sys.argv.append("--NotebookApp.open_browser=False")
sys.argv.append("--NotebookApp.password=" + passwd())
launch_new_instance()

显然,如果您愿意,可以更改参数。

Obviously you can change the arguments if you so desire.

在我的工作中,我们有一个用例就是你所说的 - 自动生成一个python文件,然后为用户加载一个新的ipython服务器接受它。但是,这是一个非常特殊的用例 - 对于正常的调试,我建议只在iPython中启动而不是制作* .py文件,直到错误消失。

At my work we have one use case that does what you're saying--automatically generates a python file, then loads a new ipython server for the user to access it. However, it's a pretty special use case--for normal debugging, I would recommend just starting in iPython and not making your *.py file until the bugs are gone.

OR

如果您正在谈论实际上自动导航到与可用的python文件相对应的页面通过ipython笔记本服务器,然后(1)确保你使用ipython 2,并且(2)找出你想要的url是什么(它应该是确定性的)和(3)使用 webbrowser模块导航到该网址。

If you're talking about actually automatically navigating to the page that corresponds to a python file made available by an ipython notebook server, then (1) make sure you're using ipython 2, and (2) figure out what you're desired url is (it should be deterministic) and (3) use the webbrowser module to navigate to that url.

这篇关于用python文件启动ipython notebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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