Using .NET Core in Jupyter Notebook
Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations, and narrative text. It can be used as a tool for interactively developing and presenting data science projects. Mostly, it is used with Python and R which are scripting languages. However, it can also be used with compiled languages, such as .NET programming languages, Go, and Julia. For a list of supported programming languages, please refer to the Jupyter kernels page in GitHub.
This article explains steps to set up Jupyter Notebook for .NET Core programming languages on Windows 10. It is based on the .NET Notebooks Preview 2 that supports C#, F#, and PowerShell. This article also provides few C# examples that demonstrate how to use DataFrame and Charts.
Microsoft .NET Core
.NET Core is an open-source and cross-platform software framework that can run on various operating systems, such as Windows, Linux, and macOS. It is a project of the .NET Foundation and released under the MIT and Apache 2 licenses.
The first version (.NET Core 1.0) was released on June 27, 2016. At the time of this writing, the current version is .NET 5.0 released on November 10, 2020. In .NET 5.0, the “Core” has been dropped from the name to emphasize that this is the main implementation of .NET going forward and it supports more types of applications and more platforms than .NET Core or .NET Framework.
Currently, Microsoft supports the .NET Core 2.1, .NET Core 3.1, and .NET 5.
Next, I will demonstrate steps to set up Jupyter Notebook for .NET Core 3.1 on Windows 10.
Steps to Setup Jupyter Notebook for .NET
1. Install Python
Python packages are available on the Python website. It supports many operating systems, such as Windows, Linux/Unix, and Mac OS X.
Download the Windows version and then install it on the machine. In this article, Python 3.9.4 64bit is used. You need to verify the installation path or choose the Add Python 3.9 to PATH option to add the Python installation path to the PATH environment variable. However, the Add Python 3.9 to PATH option may introduce the version conflicts among the installed Python versions. If you have multiple versions of Python installed on the machine, please be cautious of this option.
After installing, open the Windows Command Prompt to verify the version of Python (python –version).
You may install different Python Distributions, such as Anaconda. Please refer to the Anaconda website for more information.
2. Install Jupyter Notebook
Jupyter Notebook can be installed with the pip command. Open the Windows Command Prompt and use the following commands to install Jupyter Notebook.
python -m pip install --upgrade pip python -m pip install jupyter
Then, run ‘Jupyter notebook’ from the Windows Command Prompt to start the Jupyter Notebook.
At this time, the Jupyter Notebook only supports Python 3.
For different Python distributions, please refer to the distribution websites regarding how to install Jupyter Notebook.
3. Install .NET Core 3.1
You can download .NET Core 3.1 from the .NET Core website.
After the installation was successful, run the ‘
dotnet ––version‘ command in the command prompt to verify the version of .NET Core.
4. Install dotnet-interactive Kernel
.NET on the Jupyter Notebook relies on the Microsoft.dotnet-interactive package which is a command-line tool for interactive programming with C#, F#, and PowerShell, including support for Jupyter Notebooks.
Run the following command in the command prompt to install Microsoft.dotnet-interactive.
dotnet tool install --global Microsoft.dotnet-interactive --version 1.0.155302
The versions higher than 1.0.155302 are for NET 5.0.
Then, run the following command to add dotnet-interactive to the Jupyter Notebook.
dotnet interactive jupyter install
Finally, run ‘jupyter notebook’ via the Windows Command Prompt. Now, the Jupyter Notebook supports C#, F#, and PowerShell programming languages.
You can refer to the following examples that show how to use C# in Jupyter Notebook.
- Getting Started with C# DataFrame and XPlot.Plotly: This example demonstrates how to use DataFrame in Microsoft.Data.Analysis package and XPlot.Plotly library to plot charts.
- Getting Started with Eikon Data API .NET in Jupyter Notebook: This example demonstrates how to use Refinitiv .NET Eikon Data API on Jupyter Notebook to retrieve the latest data, historical data, symbology, and news. It uses the EikonDataApi package to retrieve data from Eikon and uses XPlot.Plotly package to draw charts.
1. En.wikipedia.org. 2016. .NET Core – Wikipedia. [online] Available at: <https://en.wikipedia.org/wiki/.NET_Core> [Accessed 28 April 2021].
2. Microsoft. n.d. .NET Core and .NET 5 official support policy. [online] Available at: <https://dotnet.microsoft.com/platform/support/policy/dotnet-core> [Accessed 28 April 2021].
3. Docs.microsoft.com. n.d. .NET introduction and overview. [online] Available at: <https://docs.microsoft.com/en-us/dotnet/core/introduction> [Accessed 28 April 2021].
4. Python.org. 2021. Download Python. [online] Available at: <https://www.python.org/downloads/> [Accessed 28 April 2021].
5. Nuget.org. n.d. Microsoft.dotnet-interactive 1.0.221505. [online] Available at: <https://www.nuget.org/packages/Microsoft.dotnet-interactive/> [Accessed 28 April 2021].
6. Naggaga, M., 2020. .NET Interactive is here! | .NET Notebooks Preview 2 | .NET Blog. [online] .NET Blog. Available at: <https://devblogs.microsoft.com/dotnet/net-interactive-is-here-net-notebooks-preview-2/> [Accessed 28 April 2021].
7. Docs.microsoft.com. n.d. What’s new in .NET 5. [online] Available at: <https://docs.microsoft.com/en-us/dotnet/core/dotnet-five> [Accessed 28 April 2021].
Credit: Source link