Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How VS Code uses Jupyter Notebook

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article analyzes how VS Code uses Jupyter Notebook. The content is detailed and easy to understand. Friends interested in "VS Code how to use Jupyter Notebook" can read it slowly and deeply according to the idea of Xiaobian. I hope it can help everyone after reading. Let's learn how to use Jupyter Notebook with VS Code.

Selected from Towards Datascience

While many programmers choose to work in an IDE (Integrated Development Environment), there are some programmers (including me) who like to explore different possibilities in an IDE. This exploration is not just cool, but because each popular IDE has its own unique features, and many of my projects are collaborations with colleagues who may use different IDEs, and I try to use their "language" in order to work together in the project.

When it comes to Python, I prefer to program in Jupyter Notebook and Visual Studio (VS) Code.

Jupyter Notebook has become an extremely popular choice among IDEs. In addition to IPython, there are other kernels available. In addition to Python, Jupyter Notebook supports Java, R, Julia, and other popular programming languages. Jupyter Notebook integrates both Markdown text and executable source code, making it easier to collaborate on replicable team projects.

VS Code is another open source IDE popular among developers using multiple programming languages such as JavaScript, C#, and Python, and the list of languages VS Code can support continues to grow as VS Code plugins continue to be developed. But it also doesn't support editing Jupyter Notebook generated files.

It's different now. With the latest release of the VS Code Python plugin in 2019, VS Code has provided native support for Jupyter Notebook, meaning you can work on a notebook without running Jupyter Notebook. I'll cover the basics of using Jupyter Notebook in VS Code.

environment settings

You need to install Jupyter packages on your computer first. You can install it with python installer (pip install notebook) or conda installer (conda install -c conda-forge notebook). Of course, you also need VS Code and Python 3 on your computer. If not, go to these two websites first.

Python 3:https://www.python.org/downloads/

VS Code:https://code.visualstudio.com/download

Open VS Code and go to Extension. If you're on Mac, you can open extensions with the X (Shift + Cmd + X) shortcut, or Ctrl + Shift + X if you're on Windows. Search for "Python" in the text box and you should see a list of related extensions. Click on the extension called Python-an extension developed by Microsoft. Install this extension and restart VS Code if necessary.

After completing the last few preparatory steps, VS Code is ready to use Jupyter Notebook.

Creating Jupyter notebooks

To create a new Jupyter notebook, click View -> Command Palette (which can be quickly opened with P if you are using Mac). After the next page pops up, search for "Jupyter" and select "Python: Create Blank New Jupyter Notebook" option to create a new Notebook. To give you a better idea, I created a notebook called JupyterExample.ipynb, and the flow is shown below.

common operations

Insertion and deletion of cells

You can insert cells by clicking the plus sign in the toolbar or to the left of each cell. If you want to delete, click on the delete sign on the right side of the cell (small trash can).

Conversion unit content type and status

Click on the code/markdown section of the cell to convert the content type. If you want to change the state of the cell, the stand-alone text entry box puts it into edit mode. Click on the vertical bar on the left of the cell to change it to command mode. Then click on another cell, and the previously selected cell returns to the unchecked state. The vertical bar on the left side of the cell shows the status of the cell.

Shortcuts in Command State

When the vertical bar on the left side of the cell indicates that it is in command status (blue), the following shortcuts are available.

Run code blocks

You just need to click on the triangle symbol in the code/markdown field to run the code block. If you want to run all the code blocks in the notebook, just click on the double arrow sign in the top toolbar.

Although not shown in the above image, the toolbar has a triangle symbol with an upward arrow. Clicking on this symbol will run all the boldcodes in front of the current cell. If the arrow is downward, all subsequent code is run, including the current unit.

variable previewer

To view a list of defined variables, simply click the Variables button in the toolbar and a table appears showing all defined variables. Your newly defined variables are automatically included in the table.

chart preview

As shown below, we can click on the chart logo in the corner of the output image to preview all the images you have drawn.

In the image previewer, you can see a toolbar at the top. This toolbar has common functions, such as zooming in and out, saving images, etc. About VS Code how to use Jupyter Notebook to share here, I hope the above content can make everyone improve. If you want to learn more, please pay more attention to the updates of Xiaobian. Thank you for your attention to the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report