Python 将 Jupyter 笔记本会话加载到 Spyder 的最佳方法是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44588145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:10:55  来源:igfitidea点击:

What is the best method to load a Jupyter notebook session into Spyder?

pythonjupyterspyder

提问by DougR

Edit: See Spyder Notebook Plugin... https://github.com/spyder-ide/spyder-notebook

编辑:请参阅 Spyder Notebook 插件... https://github.com/spyder-ide/spyder-notebook



I would like to load a Jupyter notebook into Spyder and activate the current Jupyter Python kernel in an Spyder Ipython console. I was hoping this would allow me to use the Spyder editor, console and variable explorer whilst developing in Jupyter. Using the code below in Jupyter, I have been able to load up a converted notebook. In addition, I can open the current kernel in a new console manually. However, the variable explorer doesn't display variables from the connected console.

我想将 Jupyter notebook 加载到 Spyder 并在 Spyder Ipython 控制台中激活当前的 Jupyter Python 内核。我希望这能让我在 Jupyter 中开发时使用 Spyder 编辑器、控制台和变量资源管理器。在 Jupyter 中使用下面的代码,我已经能够加载转换后的笔记本。此外,我可以手动在新控制台中打开当前内核。但是,变量资源管理器不会显示来自连接控制台的变量。

I would like to:

我想要:

1) From Jupyter, automatically open the current Jupyter kernel in the Spyder IPython Console
2) Get the Spyder variable explorer to work with a connected kernel

1) 从 Jupyter,在 Spyder IPython 控制台中自动打开当前的 Jupyter 内核
2) 获取 Spyder 变量资源管理器以使用连接的内核

Any ideas? Does anyone have a better method than that listed below?

有任何想法吗?有没有人有比下面列出的更好的方法?



Open Jupyter notebook and kernel in Spyder:

在 Spyder 中打开 Jupyter notebook 和内核:

Get current notebook name

获取当前笔记本名称

%%javascript
var nb = IPython.notebook;
var kernel = IPython.notebook.kernel;
var commandFileName = "theNotebook = " + "'"+ nb.notebook_path +"'";
kernel.execute(commandFileName);

Convert notebook to plain python script

将笔记本转换为纯 python 脚本

get_ipython().system('jupyter nbconvert --to script "' + theNotebook + '"')

Open python script in Spyder

在 Spyder 中打开 python 脚本

get_ipython().system('spyder "' + theNotebook.replace('.ipynb', '.py') + '"')

Get kernel json connection file

获取内核json连接文件

import ipykernel
print("Copy and paste this into Spyder diaolgue box:\nConsoles~'Connect to an existing kernel':\n")
print(ipykernel.connect.get_connection_file())

回答by Carlos Cordoba

(Spyder developer here) This will be solved once we make our own Notebook pluginto start Spyder kernels.

这里Spyder 开发人员)一旦我们制作了自己的Notebook 插件来启动 Spyder 内核,这个问题就会解决。

We're working right now to release a first version of that plugin with good desktop integration. Then we'll proceed to integrate it with the other Spyder plugins (such as the Variable Explorer) and for that we need to make the notebook to start Spyder kernels.

我们现在正在努力发布具有良好桌面集成的插件的第一个版本。然后我们将继续将其与其他 Spyder 插件(例如变量资源管理器)集成,为此我们需要制作笔记本以启动 Spyder 内核。

回答by Kumar Gaurav

To install this plugin, you can use either pip or conda package managers, as follows:

要安装此插件,您可以使用 pip 或 conda 包管理器,如下所示:

Using conda (the recommended way!):

使用 conda(推荐的方式!):

conda install spyder-notebook -c spyder-ide

conda 安装 spyder-notebook -c spyder-ide

Using pip:

使用点子:

pip install spyder-notebook

pip 安装 spyder-notebook

Web: https://github.com/spyder-ide/spyder-notebook

网址:https: //github.com/spyder-ide/spyder-notebook

回答by Bakr Frag

use any IDE or editor within anaconda interpreter i use it within pycharm and performance well

在 anaconda 解释器中使用任何 IDE 或编辑器我在 pycharm 中使用它并且性能良好