Jupyter Notebook In Visual Studio Code



  1. Jupyter Notebook Vs Visual Studio Code
  2. Jupyter Vscode

Few days back, I decided to setup development environment for deep learning on my Windows 10 laptop. In this article, I would share my experience in setting up a system typically for Data Science developers. Although I used Windows 10 but the steps will be same for Linux and Mac OS.

Jupyter Notebook quick start. The Python extension and the Jupyter extension work together to give you a great Notebook experience in VS Code. Open or create a Jupyter Notebook file (.ipynb) and start coding in our Notebook Editor! For more information you can: Follow our Python tutorial with step-by-step instructions for building a simple app. How is Notebook Mode different than Jupyter Notebooks/Jupyter Lab. Jupyter Notebooks have the file extension.ipynb and require the Jupyter runtime in order to run them. Notebook Mode only requires Visual Studio Code and the PowerShell extension – two things that most PowerShell users have already. Working with Jupyter Notebooks in Visual Studio Code Jupyter (formerly IPython Notebook) is an open-source project that lets you easily combine Markdown text and executable Python source code on one canvas called a notebook. Visual Studio Code supports working with Jupyter Notebooks natively, as well as through Python code files. Nov 08, 2018 Run the “Import Jupyter Notebook” command in the editor and code will be extracted into a Python file, then all the rich features that make you productive are at your fingertips – including AI-powered IntelliSense (IntelliCode), integrated debugger, Visual Studio Live Share, refactoring, multi-file management, and Git source control. Within the Notebook Editor window, double-click any plot to open it in the viewer, or select the plot viewer button on the upper left corner of the plot (visible on hover). Read more about using Jupyter in Visual Studio Code.

Being a developer, need IDE for coding and not fan of browser based editor. Jupyter Notebook is favourite tool for data scientist and we can’t skip that in case of data science. Fortunately, VS Code supports Jupyter notebook. You can now directly edit .ipynb files and get the interactivity of Jupyter notebooks with all of the power of VS Code. We will go through it.


In this tutorial, we will cover the following steps:

1. Install Python
2. Install TensorFlow 2.0
3. Install Jupyter Notebook
4. Setup VS Code
5. Testing Environment
6. Virtual Environment (Optional)

1. Install Python

Download Python 3.7.6 from www.python.org(Currently, Tensorflow doesn’t support Python 3.8). I would suggest to install it with “customize installation” option and allow all users.

After installation, check the Python version on terminal. If there are multiple versions of python installed in the machine then change PATH in environment variable to the installed version and restart terminal to check version.

2. Install TensorFlow 2.0

TensorFlow is open source deep learning framework by Google, helps us to build and design Deep Learning models.
For simplicity, we will install CPU version of TensorFlow.

It will install all supportive extensions like numpy …etc.

Note: Install the GPU version of TensorFlow only if you have an Nvidia GPU. It is good and recommended for better performance. It needs to Install/Update nvidia driver, cuda toolkit, cuDNN and then run following command to install

For more information, check out the official guide here.

The next is to install Matplotlib- a Python library for 2D plotting and can work together with NumPy.

3. Install Jupyter Notebook

Jupyter Notebook is web based interactive environment for writing the code, creating & sharing files and doing visualizations as well.

run following command to install it:

Start the notebook server from the command line:

You should see the notebook open in your browser.

If you want to specify port:

4. Setup VS Code

Download and install VS Code if not already installed.

Install the following VS Code extension from the marketplace.

Note: Make sure you have installed the latest version of the extension.

First time, open the VS Code Command Palette with the shortcut CTRL + SHIFT + P (Windows) or Command + SHIFT + P (macOS) in VSCode and select “Python: Select Interpreter” command. It will display all installed versions. Select the appropriate python environment where Jupyter notebook is installed.

To create new Jupyter notebook, open VS Code Command Palette again and run the “Python: Create Blank New Jupyter Notebook” command.

Why VS Code?

– You can manage source control, open multiple files, and leverage productivity features like IntelliSense, Git integration, and multi-file management, offering a brand-new way for data scientists and developers to experiment and work with data efficiently.
Variable Explorer will help you keep track of the current state of your notebook variables at a glance, in real-time.
– You can export as Python code and do debugging and other operation like do in regular python application

5. Testing Environment

Now, it is time to test the environment.

Create a new Jupyter book in VS Code and run following code to test :

The output should be following:

6. Virtual Environment (Optional)

a) As we are going to use same environment for all so installed TensorFlow, Jupyter Notebook in global Python environment. If you want to create a separate environment for this, you can create a virtual environment by running following command:

It will create .venv directory at specified path.

b) To activate python virutal environment

Jupyter

In VS Code:

In Command Palette CTRL + SHIFT + P, Run “Python: Create Terminal“. It will open and activate the terminal in selected Python environment.

c) Now install the TensorFlow, Jupyter notebook …etc in the activated environment.

Conclusion

In this tutorial, we saw
– how to set up a Python Deep Learning development environment using TensorFlow 2.0, Jupyter Notebook and VS Code.
– how Python extension in VS Code empowers notebook development in developer way.

If you face any problems, then feel free to share them in the comment section.

Enjoy Deep Learning !!

A Visual Studio Codeextension that provides basic notebook support for language kernels that are supported in Jupyter Notebooks today. Many language kernels will work with no modification. To enable advanced features, modifications may be needed in the VS Code language extensions.

Working with Python

Whether you are on VS Code Stable or VS Code Insiders, if you would like to work with Python just make sure you're using the latest version of the Python Extension to enjoy the joint partnership of the Python and Juypter Extensions.

Please follow the Python Extension ReadMe instructions to get started and visit the Python Documentation to learn more about how the Python and Jupyter Extension are working together to provide an optimum Python notebooks experience.

Working with other Languages

The Jupyter Extension supports other languages in addition to Python such as Julia, R, and C# in VS Code Insiders with our latest Native VS Code Notebooks Experience!

Quick Start

  • Step 1. Install VS Code Insiders

  • Step 2 If not working with Python, make sure to have a Jupyter kernelspec that corresponds to the language you would like to use installed on your machine.

  • Step 3. Install the Jupyter Extension

  • Step 4. Open or create a notebook file and start coding!

  • Special Note: The Jupyter Extension in VS Code Insiders will include our Native Notebooks experience by default. Because we are running in VS Code Insiders and this build is updated every day, there may be times when our extension may fail to work at all. We do attempt to ensure that this doesn't happen frequently. If it does, we strive to provide an updated extension build by the next business day. However, if you'd like to opt out of the native experience while working in VS Code Insiders:

    • Open the command palette (Windows: Ctrl + Shift + P, iOS: Command + Shift + P) and select 'Preferences: Open Settings (JSON)'
    • Add the following code to your JSON settings:'jupyter.experiments.optOutFrom': ['NativeNotebookEditor'],

Notebooks Quick Start

  • To create a new notebook open the command palette (Windows: Ctrl + Shift + P, iOS: Command + Shift + P) and select the command 'Jupyter: Create New Blank Notebook'

  • Select your kernel by clicking on the kernel picker in the bottom right of the status bar or by invoking the 'Notebook: Select Notebook Kernel' command.

  • Change the cell language by clicking the language picker or by invoking the 'Notebook: Change Cell Language' command.

Useful commands

Notebook

Jupyter Notebook Vs Visual Studio Code

Open the Command Palette (Command+Shift+P on macOS and Ctrl+Shift+P on Windows/Linux) and type in one of the following commands:

CommandDescription
Jupyter: Create New Blank NotebookCreate a new blank Jupyter Notebook
Notebook: Select Notebook KernelSelect or switch kernels within your notebook
Notebook: Change Cell LanguageChange the language of the cell currently in focus
Jupyter: Export to HTML Jupyter: Export to PDFCreate a presentation-friendly version of your notebook in HTML or PDF

To see all available Jupyter Notebook commands, open the Command Palette and type Jupyter or Notebook.

Feature details

Learn more about the rich features of the Jupyter extension:

  • IntelliSense: Edit your code with auto-completion, code navigation, syntax checking and more!

    • May be limited due to kernelspec of choice
  • Jupyter Notebooks: Create and edit Jupyter Notebooks, add and run code/markdown cells, render plots, create presentation-friendly versions of your notebook by exporting to HTML or PDF and more!

Supported locales

The extension is available in multiple languages: de, en, es, fa, fr, it, ja, ko-kr, nl, pl, pt-br, ru, tr, zh-cn, zh-tw

Questions, issues, feature requests, and contributions

Jupyter Vscode

  • If you have a question about how to accomplish something with the extension, please ask on Stack Overflow. Our wiki is also updated periodically with useful information.

  • Any and all feedback is appreciated and welcome! If you come across a problem with the extension, please file an issue.

    • If someone has already filed an issue that encompasses your feedback, please leave a 👍/👎 reaction on the issue.
  • Contributions are always welcome! Please see our contributing guide for more details.

  • If you're interested in the development of the extension, you can read about our development process

Data and telemetry

The Microsoft Jupyter Extension for Visual Studio Code collects usagedata and sends it to Microsoft to help improve our products andservices. Read ourprivacy statement tolearn more. This extension respects the telemetry.enableTelemetrysetting which you can learn more about athttps://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting.