使用选定的浏览器启动 IPython 笔记本

2023-07-22Python开发问题
5

本文介绍了使用选定的浏览器启动 IPython 笔记本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用非默认浏览器(在我的情况下为 Firefox)启动 IPython并认为我可以复制 in this blog

I am trying to start IPython with a non default browser (in my case Firefox) and thought I could replicate the replicate the script given in this blog

我使用的是 Windows 7

我把下面的代码放在一个文件中,比如module.py"

I put the following code in a file say "module.py"

import subprocess
subprocess.call("ipython notebook --no-browser", shell=True)
subprocess.call([r'C:Program Files (x86)Mozilla FirefoxFirefox.exe', '-new-tab', 'http://127.0.0.1:8888/'])

但是当我从命令行运行它时

However when I run it from the command line

 python C:UsersmugabalDesktopmodule1.py

它执行第一行但不执行第二行(两行单独工作正常)

It execute the first line but not the second one (both lines work fine individually)

我的问题(更笼统地说)如何启动一个进程并告诉它不要劫持控制台窗口?

My question (in a more general term) how can I launch a process and tell it not to highjack the console window?

如果我监督了一个明显的解释,我提前道歉,但我查看了子流程文档和这个平台

I apologize in advance if I have overseen an obvious explanation but I looked both in the subprocess documentation and on this platform

----- 更新 -----

我应该补充一点,我尝试使用选定的浏览器启动 IPython,但不知道如何让它工作

I should have added that I tried to launch IPython with selected browser but could not figure out how to get it work

>ipython notebook --browser='C:Program Files (x86)Mozilla FirefoxFirefox.exe'
... 
[NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/
...
**[NotebookApp] No web browser found: could not locate runnable browser.**

确切地说,Windows 命令提示符窗口中的以下命令按预期工作:

To be precise, the following command in a Windows command prompt window works as expected:

start firefox 

但是

ipython notebook --browser=firefox 

不起作用(与上述相同的错误).

does not work (same error as above).

推荐答案

我在 windows 上遇到了同样的问题,然后就这样解决了:

I had the same problem on windows and got it work this way:

  • 使用命令创建配置文件ipython配置文件创建默认

编辑 ipython_notebook_config.py 文件,搜索行

Edit ipython_notebook_config.py file, search for line

#c.NotebookApp.browser =''

替换成

import webbrowser
webbrowser.register('firefox', None, webbrowser.GenericBrowser('C:\Program Files (x86)\Mozilla Firefox\firefox.exe'))
c.NotebookApp.browser = 'firefox'

那么它对我有用.

希望对你有所帮助.

JPG

这篇关于使用选定的浏览器启动 IPython 笔记本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11