【问题标题】:How connect to Jupyter notebook with Visual Studio 2017如何使用 Visual Studio 2017 连接到 Jupyter 笔记本
【发布时间】:2019-08-13 11:19:23
【问题描述】:

Visual Studio Code 可以选择连接到 jupyter notebook。完成后,我可以通过单击 shift+enter(或其他快捷方式)来执行我的脚本,然后在 python 交互中会有 jupyter notebook 执行结果,例如。如果我使用 matplotlib 图,我可以在 python 交互中显示这个图。我尝试为 Visual Studio 2017 找到相同的解决方案(与 jupyter notebook 集成),根据我的示例,我想在 Visual Studio 2017 python 交互式窗口(我想它连接到 jupyter notebook)中显示我的 matplotlib 图。可能吗?这是正确的方法吗?

我不是在质疑如何在 Visual Studio 2017 中使用 IPYNB 文件,我的问题是如何将我的 python 脚本作为 jupyter notebook 执行?

如果我有像 this 这样的 python 脚本

import matplotlib.pyplot as plt
import numpy as np
def f(t):
    'A damped exponential'
    s1 = np.cos(2 * np.pi * t)
    e1 = np.exp(-t)
    return s1 * e1

t1 = np.arange(0.0, 5.0, .2)

l = plt.plot(t1, f(t1), 'ro')
plt.setp(l, markersize=30)
plt.setp(l, markerfacecolor='C0')

plt.show()

并在 Visual Studio Code 中使用 shift + Enter 执行此脚本 我在 python 交互式窗口中有我的结果图。 如果我在 Visual Studio 2017 中使用 Python Interactive 中的 Debug->Execute File 执行相同的脚本,则结果图位于 python 交互式窗口之外。在 Visual Studio 2017 中,我使用 Anaconda 5.2.0 作为 Python 环境。 如何解决这个问题?

【问题讨论】:

标签: python visual-studio visual-studio-code visual-studio-2017 jupyter-notebook


【解决方案1】:

试试 '%matplotlib inline'。这就是我们在 VS Code 扩展中用来强制绘图显示在交互式窗口中的方法。

【讨论】:

    【解决方案2】:

    根据this 教程,我做了一些步骤来解决问题。在 Anaconda 5.2.0 环境下的 Visual Studio 2017 Python 环境窗口中,我在下拉列表中选择概览,然后选择使用 IPython 交互模式复选框并重置 Python 交互窗口。一般来说,问题的解决方法是使用引用教程中描述的IPython模式。

    IPython 模式下的 Visual Studio 交互窗口是高级的 用户友好的交互式开发环境,具有 交互式并行计算功能。

    【讨论】:

      猜你喜欢
      • 2021-02-16
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      • 2022-12-30
      • 2020-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多