Search code examples
pythonvisual-studiovisual-studio-codevisual-studio-2017jupyter-notebook

How connect to Jupyter notebook with Visual Studio 2017


Visual Studio Code has option to connect to jupyter notebook. When it's done I can execute my script by clicking shift+enter (or other shortcut) then there is jupyter notebook execution result in python interactive, eg. if I use matplotlib plot I can show this plot inside python interactive. I try to find same solution (integration with jupyter notebook) to Visual Studio 2017, according to my example I want to show my matplotlib plot in Visual Studio 2017 python interactive windo (which is connected to jupyter notebook I suppose). Is it possible? Is it correct approach?

I am not questioning how I can work with IPYNB file inside Visual Studio 2017, my question is rather how I can execute my python script as jupyter notebook execution?

If I have python script like this

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()

and execute this script in Visual Studio Code with shift + Enter I have my result plot in python interactive window. If I execute same script in Visual Studio 2017 with Debug->Execute File in Python Interactive then the result plot is outside python interactive window. Inside Visual Studio 2017 I use Anaconda 5.2.0 as Python Enviroment. How to resolve this problem?


Solution

  • According to this tutorial I do some step to solve question problem. In Visual Studio 2017 Python Environments Window under Anaconda 5.2.0 enviroment I select Overview in dropdown list then I select Use IPython interactive mode checkbox and reset Python Interactive Window. Generally, the solution of the problem is to use IPython mode as described in quoted tutorial.

    The Visual Studio Interactive window in IPython mode is an advanced yet user-friendly interactive development environment that has Interactive Parallel Computing features.