Understand the configuration and use of Jupyter in one article (hard work version)

Jupyter is a web-based interactive computing platform that enables users to create and share documents containing live code, equations, visualizations, and explanatory text. Jupyter is widely used in the field of data analysis. It provides an intuitive and interactive operation interface, making it easier for users to explore data, visualize data, and conduct experiments on data processing and modeling.

Jupyter can not only display and format Python code, but also save the user's historical code and results as well as data analysis results. These results can be viewed and modified at any time later, making the learning and application of Python more convenient and efficient.

In short, it is very necessary and convenient to learn jupyter. The operation of this article is mainly for Windows system.

1. Install Jupyter

The installation is very simple. There are generally two ways, one is the python environment, and the other is the Anaconda environment;

1.1 Install in Python environment

  1. Install Python. Download the latest version of Python from the official Python website [ 1 ].

  2. Install pip. pip is Python's package management tool for installing and managing Python packages. Enter the following command at the command line to check whether pip is installed:

    pip --version
    

    If pip has been installed, it will output the version information of pip, otherwise it needs to be installed manually.

  3. Install Jupyter Notebook. Use the pip command to install Jupyter Notebook. Enter the following command in a command prompt or terminal window:

    pip install jupyter
    

    Wait for a while, and Jupyter Notebook will be installed on your computer.

  4. Start Jupyter Notebook. Once installed, start Jupyter Notebook by entering the following command in a command prompt or terminal window:

    jupyter notebook
    

    This command will automatically open your default browser, display the home page of Jupyter Notebook, and start a Jupyter kernel (Kernel) in the background.

1.2 Install in Anaconda environment

Normally, when installing Anaconda, jupyter is installed along with anaconda, and there is no need to follow the steps below to install it;

  1. Install Anaconda. Download the latest version of Anaconda from the official Anaconda website [ 3 ].

  2. Start Anaconda Navigator. After the installation is complete, start Anaconda Navigator, which is a visual application that facilitates users to manage and run various tools and applications included in Anaconda.

  3. Install Jupyter Notebook. In Anaconda Navigator, click "Environments" in the left navigation bar, then select the environment where Jupyter Notebook needs to be installed in the area on the right, search for "jupyter" in the "Packages" tab below, and check "jupyter" and "notebook". Then click the "Apply" button to install.

    image-20230423155830561

  4. Start Jupyter Notebook. After the installation is complete, click the "Launch" button in Anaconda Navigator to start Jupyter Notebook, or enter the following command in the command prompt or terminal window to start:

    jupyter notebook
    

2. Start command

  • default port start

    jupyter notebook
    

    By default, the address bar of the browser will display: http://localhost:8888/tree. Among them, "localhost" refers to the local machine, and "8888" refers to the port number. Every time it is started again, the port number can be analogized.

  • Start the specified port

    jupyter notebook --port <port_number>
    指定端口号只有数字,不含 <>
    
  • Start the server without opening the browser

    jupyter notebook --no-browser
    

    The terminal will display the link to open the browser. If you need to start the browser, just copy the link and open it

3. Configuration file storage location

The startup directory of Jupyter Notebook refers to the default working directory when Jupyter Notebook executes the service. When you create a new file in Jupyter Notebook, it will create the file in this directory by default.

Setting the startup directory of Jupyter Notebook is very useful, especially if your project has a lot of data or code scattered in different directories. By setting the startup directory as your project root directory, you can manage and access these data or codes more easily.

For example, suppose you have a project called "my_project" that contains several subdirectories and data files. If you set the startup directory of Jupyter Notebook to the "my_project" directory, then you can easily access any file in this project without entering the full path in Jupyter Notebook.

In addition, in Jupyter Notebook, you can use some Python libraries to process and visualize your data. If you are using relative paths to access data files, it is often more convenient to use paths relative to the startup directory than absolute paths.

Jupyter default files are placed in the user directory, as shown in the figure below, you can see the startup directory when you start it; entering jupyter is indeed the content of this directory; obviously this is problematic, so we need to change the storage location of the file;

image-20230423113443692

image-20230423113524823

  • Create a new target folder

    Create a new directory where you want to put these files, for example, my directory is:D:\Coding\Jupyter_PyProject

  • View configuration file path

    Enter this line of command in the command window, or enter this line of command in the command window in your corresponding python environment, to view the default configuration file location; but although this command can be used to view the path where the configuration file is located, the main purpose is Whether to replace the configuration file under this path with the default configuration file (equivalent to reset)

    jupyter notebook --generate-config
    

    image-20230423114534766

  • Modify the configuration file

    The location of the configuration file is found above, now we only need to open this file, and then edit it; windows is more convenient, you can open it with Notepad, but it may be a bit troublesome to find the target code, here use notepad++ to open; directly Ctrl+ F Search keywords c.NotebookApp.notebook_dir, you can find the target code line;

    image-20230423115246543

    After finding this line of code, cancel the comment, and write the address of the directory created in advance to store the file in single quotation marks, save and exit;

    image-20230423115545054

  • Restart jupyter to verify the configuration;

    You can see that the modification has been successful here;

    image-20230423133121188

  • there is a pit

Here I want to emphasize opening through commands and opening through the shortcuts provided when installing anaconda, because there are pitfalls here. When you install Anaconda, you will find that you can open a jupyter using commands and shortcuts. These two ways to open It is different. For example, the startup directory of jupyter has been modified, but after opening it with a shortcut, the startup directory is still the default directory; for specific differences, please refer to the Q&A section below;

4. Interface function

  • Files

    image-20230423214418700

  • Running

    The Running tab shows the currently running kernel and Jupyter Notebook processes. Specifically, the Running tab will list all currently running Notebooks, including its name, directory, path to the Noteboook file, state of the kernel, connected users, and its startup time.

    Through the Running tab, you can easily view the opened notebooks, and you can choose to close them in different ways (closing the notebook will not shut down the kernel), such as stopping the kernel, restarting the kernel, deleting the notebook, opening the terminal, and viewing the startup log of the notebook wait. In addition, the Running tab also provides some advanced features, such as bundling multiple Notebooks into a single service, configuring and managing Jupyter Notebook servers, and more.

    image-20230423213901301

  • Clusters

    In Jupyter Notebook, the Clusters tab refers to a component of Jupyter Notebook, which is an interactive interface provided by the IPython parallel package for distributing tasks and coordinating calculations among multiple computers. Specifically, the Clusters tab allows users to connect to one or more remote IPython cores (IPython engines) and distribute computing tasks among these cores.

    In the Clusters tab, users can manage clusters by adding, deleting, starting, stopping, and connecting to IPython clusters. Once connected to a cluster, users can distribute computing tasks among individual cores to maximize simultaneous use of CPU and memory resources of multiple computers. The Clusters tab also provides some additional features, such as viewing cluster status, monitoring workload and task progress, etc.

    Generally don't...

  • editor interface

    Here is a picture of another blogger, the original text: https://zhuanlan.zhihu.com/p/441668517

    In fact, it is relatively clear, but if you are still not familiar with it, just translate it, and the translation of the webpage is ok. As for Sinicization, there are many methods on the Internet, but I have not succeeded anyway.

    img

5. Theme extension

5.1 Configuration method

  • Install

    Use pip to install theme extensions

    pip install jupyterthemes
    
  • Load the list of available themes

    jt -l
    

    image-20230424024640368

  • apply a theme

    The topic name here is the topic name in the topic list above. If the command reports an error, see the solution below;

    jt -t 主题名称
    
  • advanced configuration

    jt -t 主题名称 -f 字体名称 -fs 字体大小 -cellw 代码单元格宽度 -T 工具栏 -N 笔记本名称
    

    See the official website for details: https://github.com/dunovank/jupyter-themes

  • restore default theme

    jt -r
    
  • The jt command is not available solution

    After installing jupyter themes, run the jt command, the error is as follows

    jt : 无法将“jt”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再
    试一次。
    所在位置 行:1 字符: 1
    + jt -l
    + ~~
        + CategoryInfo          : ObjectNotFound: (jt:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    

    The solution is to configure the environment variables, open the environment variables - click system variables - click PATH - create;

    Of course, the path here should be consistent with your local environment;

    If you don’t know the path, you can open the command window; switch to jupyter themesthe environment you installed (you don’t have multiple virtual environments installed, or your jupyter is installed in the default environment, don’t worry), run pip show jupyterthemes;

    Finally, don't locate site-packagesthe directory, but locate Scriptsthe directory;

    image-20230424115314361

    image-20230424114627808

5.2 List of Topics

  • chesterish

    image-20230424025431263

  • grade3

    image-20230424025535652

  • mining box

    image-20230424025718565

  • mining box

    image-20230424025811441

  • monokai

    image-20230424025838515

  • oceans16

    image-20230424025910536

  • onedork

    image-20230424025939437

  • solarizedd

    image-20230424030010676

  • solarizedl

    image-20230424030037606

6 function expansion

6.1 Associate Anaconda environment

6.1.1 Introduction and Installation

nb_condais a Jupyter Notebook plugin that enables access to Conda environments and packages in the Notebook. In Jupyter's file browser, nb_condathe extension adds a Conda tab that can be clicked to view a list of existing Conda environments. Through nb_conda, users can easily create, use and share their own Conda environment in Notebook.

  • Install

    conda install nb_conda
    
  • uninstall

    canda remove nb_conda
    

6.1.2 Introduction to use

  • Select the conda navigation bar to display the anaconda environment and packages;

    image-20230425203312630

  • Kernel selection

    image-20230425203521053

6.2 Extended library

6.2.1 Introduction and Installation

The extension library generally involves two things, one is jupyter_nbextensions_configuratorand the other is jupyter_contrib_nbextensions;

jupyter_nbextensions_configuratoris a GUI tool for managing and configuring Jupyter Notebook's notebook extensions. It provides a Graphical User Interface (GUI) to enable, disable and configure the nbextensions extension for Jupyter Notebook. It also allows you to use predefined options to configure these extensions to better suit your needs. In addition, it provides some themes to change the notebook style and interactive experience.

jupyter_contrib_nbextensionsis a collection of extensions that can be used to enhance the functionality of Jupyter Notebooks. These extensions contain various types of utilities such as code folding, highlighting, table sorting, navigation bars, and more. By installing jupyter_contrib_nbextensions, you can manage your notebook more conveniently and improve programming efficiency. Note that jupyter_contrib_nbextensions includes the nbextensions_configurator tool.

  • pip install

    pip install jupyter_contrib_nbextensions
    jupyter contrib nbextensions install --user
    pip install jupyter_nbextensions_configurator
    jupyter nbextensions_configurator enable --user
    
    
  • conda install

    conda install -c conda-forge jupyter_contrib_nbextensions
    jupyter contrib nbextension install --user
    conda install -c conda-forge jupyter_nbextensions_configurator
    jupyter nbextensions_configurator enable --user
    
  • After installation, I found that there are only four or five in the extension library.

    Uninstall the extension library and reinstall it again. It is recommended to run the command line by line;

    • pip uninstall

      pip uninstall jupyter_contrib_nbextensions
      
    • anaconda uninstall

      conda remove jupyter_nbextensions_configurator
      
  • After installation, start jupyter and you can see nbextensions. You need to cancel the selection in the picture to use it; to use it, just select it in front of the corresponding extension;

    image-20230425202953077

6.2.1 Extended Recommendations

  1. Table of Contents: Automatically generate the table of contents in the document, which is convenient for quick navigation and finding content. [ 1 ]

    img

  2. Collapsible Headings: Collapses and expands cell headings, saving page space and making the entire document easier to navigate. [ 2 ]

  3. Code Folding: You can collapse code blocks in code cells, helping to hide unnecessary details and improve readability. [ 3 ]

  4. ExecuteTime: Displays the execution time of the code cell. [ 4 ]

    image-20230425202405625

  5. Notify: Push notification to the browser when code execution completes. [ 5 ]

Source of some content and pictures: https://cloud.tencent.com/developer/article/2135662

7. Basic use

Put two links first, for more details, see:

  • Two modes of Jupyter Notebook notebook

    • command mode

      The command mode combines keyboard commands with Jupyter Notebook notebook commands, and you can run notebook commands through combinations of different keys on the keyboard.
      Press the esc key to enter command mode.
      In command mode, the left border is a thick blue line.

    • edit mode

      Edit mode enables users to edit code or documentation within a cell.
      In edit mode, the cell border and the left border line are both green.

    image-20230426004005339

  • Delete cell shortcut : Double-click the D key after entering command mode

  • Restore cells : press the Z key after entering command mode

  • Shift-Enter : Run this unit, select the next unit

  • Ctrl-Enter : run this unit

  • Alt-Enter : run this unit, insert a new unit below it

  • Load the source code from the specified location

    I want to directly load the source code at the specified location into the notebook in Jupyter Notebook;

    Enter the following command to run it to load, after running, the code will be loaded into the cell, and the command will be commented;

    %load URL
    

    image-20230426003030312

  • More magic commands

    The above is an application of the magic command, and there are other commands like obtaining the current file location, etc. For more information, refer to the official website: https://ipython.readthedocs.io/en/stable/interactive/magics.html

8. Actual combat

8.1 A simple drawing

#!/usr/bin/env python
# coding: utf-8

# In[1]:


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


# In[2]:


# 创建测试数据
df = pd.DataFrame({
    
    
    'year': [2016, 2017, 2018, 2019, 2020],
    'sales': [100, 130, 150, 170, 200]
})


# In[3]:


# 绘制柱状图
plt.bar(df['year'], df['sales'], color='blue')
plt.xlabel('Year')
plt.ylabel('Sales')
plt.title('Sales over Year')
plt.show()


# In[ ]:

The three cells respectively import packages, create test data, and draw;

The operation needs to be executed strictly in order;

image-20230426005408378

8.1 Crawl hot searches on Weibo

#!/usr/bin/env python
# coding: utf-8

# In[7]:


import requests
from bs4 import BeautifulSoup
import time


# In[18]:


headers = {
    
    
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
    'Cookie':'SUB=_2AkMTf37Hf8NxqwJRmPAVyG7jbol0wwrEieKlI48cJRMxHRl-yT9vqlYOtRB6OP9QKBlDDjMdGlMFok5NIqGTLxEXHcGr; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9W5UiecUPRV2SWjRzBIq2X0V; SINAGLOBAL=618205954960.4446.1681196722663; UOR=www.baidu.com,weibo.com,tophub.today; _s_tentry=-; Apache=5834475057987.334.1682445226156; ULV=1682445226181:3:3:1:5834475057987.334.1682445226156:1681202990452; XSRF-TOKEN=WKel-EKSczosZuoOMXKVIH9H; WBPSESS=durPiJxsbzq5XDaI2wW0N0pbOd3fbV1w3XF-VOcj7XTJ8vDiYa5jmFydo3U2yLd3wSJp3fMJK1n5h3EzWFi1ruvJTHRYOs9aoG4rZ64JjMz9qH5LbEnhw5Cxomz5i-gj'
}

url = 'https://s.weibo.com/top/summary'


# In[19]:


try:
    response = requests.get(url, headers=headers)
    response.encoding = 'utf-8'
    if response.status_code == 200:
        print(response.text)
    else:
        print(f'Request failed with status code {
      
      response.status_code}')
except RequestException as e:
    print(e)


# In[20]:


response_html = response.text


# In[21]:


soup = BeautifulSoup(response_html, 'lxml')


# In[22]:


hot_list = []


# In[23]:


items = soup.select('tbody > tr')


# In[31]:


for item in items:
    hot_title = item.select_one('.td-02 > a').get_text(strip=True)
    hot_url = 'https://s.weibo.com' + item.select_one('.td-02 > a')['href']
    hot_item = {
    
    
        'hot_title': hot_title,
        'hot_url': hot_url
    }
    hot_list.append(hot_item)


# In[43]:


for i in range(len(hot_list)):
    if i<10:
        print(i+1,hot_list[i]["hot_title"])

The specific idea is to use the requests library to send requests to the real-time hot searched pages on Sina Weibo, and parse the returned html content through the BeautifulSoup library. Then traverse each element in the html, extract the title and link of the hot search topic, and finally store it in the hot_list array. Finally, traverse the hot_list array again and output the top ten hot search topics.

It should be noted that when this code accesses the Sina Weibo website, request headers and cookies are set to prevent data from being unable to be requested due to missing necessary parameters. At the same time, since the content of the website may change at any time or there is an anti-crawler mechanism, it is necessary to perform certain fault-tolerant processing during crawling to ensure the stability of the program operation.
insert image description here

Q&A

Anaconda shortcut opens Jupyter and the startup directory opened by the command is different

The specific pit here is that the startup directory of Jupyter has been modified, but when the jupyter shortcut installed by Anaconda is opened, the startup directory opened is still the default directory, but when the command is used to open, the startup directory has been modified successfully ;

  • why ?

    On Windows, there are two ways to run Jupyter Notebook:

    1. Open Jupyter Notebook via command line.
    2. Add a shortcut on the Windows desktop to open Jupyter Notebook through the shortcut.

    The difference between these two methods is that when Jupyter Notebook is opened through the Anaconda command line, the Jupyter Notebook installed in the currently activated environment in Anaconda is started; when Jupyter Notebook is opened through a desktop shortcut, it is started in Anaconda in the specified environment Installed Jupyter Notebook.

    In order to better understand this problem, the following is a specific explanation of each file path:

    • C:\Anaconda3\python.exeis the path to the executable file for the Python interpreter that comes with Anaconda.
    • C:\Anaconda3\cwp.pyis a script file used to change the current working path to the specified path.
    • C:\Anaconda3\envs\env_nameis the path to the specified environment.
    • C:\Anaconda3\Scripts\jupyter-notebook-script.pyis the Python script file used to start Jupyter Notebook.
    • %USERPROFILE%is the path to the current user's home directory.

    After entering the Anaconda Prompt interface through the command line (or directly using PowerShell/CMD), enter the "jupyter-notebook" command, and the system will automatically find Jupyter Notebook in the currently activated Anaconda environment and start it. So in this case, there is no need to use the cwp.py script file, env_name environment path and jupyter-notebook-script.py path to specify the environment and start the script.

    However, if you want to start Jupyter Notebook from a shortcut on the desktop, you need to indicate which environment you want to run Jupyter Notebook in. In order to do this, the shortcut needs to know:

    • the location of the Python interpreter (ie C:\Anaconda3\python.exe);
    • switch environment's script location (i.e. C:\Anaconda3\cwp.py);
    • The location of the environment you want to use (i.e. C:\Anaconda3\envs\env_name);
    • The location of the Python script that starts Jupyter Notebook (ie C:\Anaconda3\Scripts\jupyter-notebook-script.py);
    • The location of the user's home directory (ie %USERPROFILE%.

    So when you start Jupyter Notebook with the desktop shortcut, the shortcut actually opens it by executing:

    C:\Anaconda3\python.exe C:\Anaconda3\cwp.py C:\Anaconda3\envs\env_name C:\Anaconda3\Scripts\jupyter-notebook-script.py %USERPROFILE%
    

    This activates the specified environment and starts the Jupyter Notebook execution service under that environment.

    For example, the path of the blogger is as follows, here D:\Coding\Anaconda3is the default python environment;

    D:\Coding\Anaconda3\python.exe D:\Coding\Anaconda3\cwp.py D:\Coding\Anaconda3 D:\Coding\Anaconda3\python.exe D:\Coding\Anaconda3\Scripts\jupyter-notebook-script.py "%USERPROFILE%/"
    
  • How to modify the startup directory of Jupyter opened by shortcut ?

    1. Open the shortcut folder, right-click the shortcut icon you want to modify, and select Properties.

    2. Under the "Shortcut" tab, find the "Target" field. The commands in the target are as follows, whether %USERPROFILE%there are double quotes included or not will not affect;

      C:\Anaconda3\python.exe C:\Anaconda3\cwp.py C:\Anaconda3\envs\env_name C:\Anaconda3\Scripts\jupyter-notebook-script.py %USERPROFILE%
      
    3. Will be %USERPROFILE%completely replaced with the path of the startup directory you set, quotation marks will not affect.

      image-20230423160732799

    4. Click the "Apply" button to save the changes, and exit the "Properties" window and you're done.

Chinese interface

There are a lot of tutorials on the Chinese interface on the Internet, such as changing configuration files, adding user variables, and adding a --NotebookApp.locale=zh_CNspecified language environment after the start command, but it has no effect after trying, but I don’t know if it is a problem with my computer environment, this has not been ruled out...

But it seems to be enough to install the extension library, but this has yet to be confirmed. I have been thinking about it for a long time, but I don’t understand it. It’s all a pit...

Netizens who know it can leave a message and tell me how it is Sinicized...

Applicable scenarios for Jupyter notebook and IDE

Applicable scenarios of Jupyter: Data processing and analysis:

  1. Data visualization: Jupyter provides an interactive visualization environment that makes data exploration easier and more intuitive.
  2. Machine Learning Modeling: Improve modeling efficiency and model accuracy by using Jupyter Notebook for data preprocessing, feature engineering, and model training.
  3. Data cleaning: Using Jupyter for data analysis and data cleaning is especially effective for large amounts of data cleaning.
  4. Data analysis: Jupyter's interactive environment makes data analysis more convenient, run the code and see the results immediately.
  5. Statistical analysis: Jupyter supports statistical analysis libraries commonly used in Python, such as NumPy, SciPy, pandas, and statsmodels.
  6. Reproducible research: With the help of Jupyter's notebook function, the experimental process is recorded and shared with colleagues or community users, which is conducive to reproducible research.
  7. Real-time data flow analysis: use the combination of Jupyter and Kafka to analyze and visualize big data in real time.
  8. Visualization of huge data sets: Using libraries such as Jupyter and Dask, large-scale data sets can be converted into visually displayed charts, which are easy for users to understand.
  9. Research Proof: Many scientists and researchers use Jupyter as a tool for exploratory research, which is very convenient and fast.
  10. Natural language processing: Use Jupyter Notebook to perform various natural language processing tasks, such as text processing, word vector generation, etc.

IDE Applicable Scenarios: Project Development:

  1. Code refactoring: IDE provides more auxiliary means, such as code completion, code formatting, automatic debugging, etc., to improve the efficiency of code refactoring.
  2. Large-scale project development: IDE supports more complex file organization, project management and version control, and can meet the needs of large-scale projects.
  3. Unit testing and integration testing: The IDE has some built-in debugging tools, such as unit testers and integration testing tools, which can help developers locate and solve problems more quickly.
  4. API development: IDE supports the development of RESTful API, which is conducive to interface design, testing and document writing.
  5. Visual interface development: IDE supports tools such as form designer to quickly create and complete the development of visual interface.
  6. Desktop software development: The IDE supports Python GUI development libraries (such as Tkinter, WxPython, etc.), which help to build desktop applications in Python.
  7. Web application development: By using IDE and web frameworks such as Flask and Django, you can build and develop web applications faster.
  8. Database application: IDE supports database operations, which facilitates the interaction between programs and RDBMS or NO-SQL databases.
  9. Multi-person collaborative development: IDE supports code version control and code hosting, which is convenient for teams to develop code collaboratively.
  10. Code reuse: Code reuse is an important means to improve development efficiency. The IDE supports packaging, publishing and sharing code libraries to speed up code writing.

Applicable project types and examples for Jupyter notebook and IDE

Projects for which Jupyter Notebook is suitable

  1. Projects in areas such as data science, machine learning, and artificial intelligence:

    These projects usually require processing large amounts of data, data preprocessing, data visualization, model development and evaluation. Using Jupyter Notebook can provide an interactive environment for data scientists and machine learning engineers to quickly experiment and iterate models, and also supports the integration of code, comments, and visualization results into one document for presentation.

    Example: Use Scikit-learn to develop and evaluate a classification model on the iris dataset.

  2. Projects such as exploratory programming and prototyping:

    These projects require quick validation of code solutions, and frequent sharing of code and documentation may be required during collaboration and analysis. Using Jupyter Notebook can easily realize the interaction between code and documents. At the same time, it supports document display in formats such as Markdown and Latex (so-called NBconvert), so that code, comments, results and documents can be integrated to facilitate team member collaboration and project management. .

    For example: To develop a simple web application using Flask, you can use Jupyter Notebook to prototype it first, and then use IDE for post-development.

  3. Projects for Teaching and Demonstrating:

    Jupyter Notebook can combine code, comments and results together as an interactive document to display and share. This makes it an excellent teaching tool for explaining and presenting data-related topics, with careful layout and thoughtful presentation in formats such as Markdown and Latex.

    For example: write a data science teaching note, including dataset introduction, data analysis process, visualization and modeling process.

IDE-suitable projects

  1. Development of large Python applications:

    The IDE is suitable for handling large-scale projects, with better code organization, architecture, debugging and performance optimization support, which can help developers better manage and maintain large-scale projects.

    For example: developing a complex web application using the Django framework.

  2. Projects for debugging, testing and performance optimization:

    The IDE provides powerful breakpoint debugging and testing support, as well as performance analysis and optimization tools, which are conducive to performance optimization and troubleshooting in scenarios such as long-running and high concurrency.

    For example: use PyCharm for debugging and CPU profiling of Python code.

  3. Projects on persistence, deployment and integration:

    The IDE supports the packaging, release, version control, and continuous integration of Python code, which has better productivity and can help developers better deploy and manage projects.

    For example: Packaging and publishing a Python application to the cloud using Visual Studio.

  4. Projects that require the use of Python's advanced features and libraries:

    The IDE provides richer editor support and various third-party plug-ins, which can easily handle advanced functions and libraries such as parallel computing, multi-thread processing, asynchronous programming, and machine learning frameworks.

    For example: use PyTorch or TensorFlow framework for the development and training of deep learning models.

Jupyter notebook installation Nbextensions does not display problems

Accompanied by this problem, there is an error report, that is, after starting jupyter notebook, the command window reports an error404 GET /static/components/marked/lib/marked.js

Solution:

Go to the python installation directory:

Lib\site-packages\nbclassic\static\components\marked\lib\

Find marked.umd.js, copy and rename marked.js directly, and restart jupyter notebook.

Can the package imported from the previous cell be used in the next cell?

can use.

In Jupyter, if a cell imports a certain Python package, then the next cell can directly use the package. This is because in Jupyter, all cells run in the same Python kernel, so resources such as variables, functions, and modules can be shared between them.

It should be noted that if an error occurs when you import the module, such as because the module does not exist or the path is set incorrectly, subsequent cells will also be affected. In addition, if you use some modules that need to be initialized, such as deep learning frameworks such as TensorFlow or PyTorch, it is recommended that you manually initialize at the beginning of each cell to avoid unexpected errors.

If you encounter the problem that the module cannot be imported correctly, you can try to manually add sys.path in the cell, and add the path of the module that needs to be imported to sys.path. For example:

import sys
sys.path.append('/path/to/module/')  # 将模块所在的路径添加到 sys.path 中
import module_name  # 导入模块

Relationship between cells in jupyter

In Jupyter Notebook, a cell is the most basic unit in which users can write code, insert text, images, tables, etc., and each cell can be regarded as an independent small program. The following relationships exist between these cells:

  1. Execution order: Cells in Jupyter Notebook are executed one by one according to their position, one by one from top to bottom. If the user splits a loop into two cells, the second cell cannot access the variables defined by the first cell, and the loop will not execute correctly.
  2. Dependency: Sometimes a cell may need the output of another cell for calculation or display. At this time, you need to run the previous cell through "Shift+Enter" to generate the output, and then run the current cell to complete Calculate or display. If the previous cell is not executed or the output result does not meet the requirements, it will cause an error in the current cell.
  3. Sequence dependency: some cells must be executed in a specific order, otherwise an error will occur. For example, when creating a chart, the data for the chart must be defined before the data can be used to draw the chart.

Original address: https://blog.jiumoz.com/archives/yi-wen-nong-dong-jupyter-de-pei-zhi-yu-shi-yong–ou-xin-li-xue-ban-

Welcome to follow the blogger's personal mini program!

Guess you like

Origin blog.csdn.net/qq_45730223/article/details/130377518