Jupyter Executes Last Cell Executed Again
Run and debug Jupyter notebook lawmaking cells
You can execute the code of the notebook cells in many means using the icons on the notebook toolbar and cell toolbars, commands of the code cell context carte (right-click the code prison cell to open information technology), and the Run commands of the main menu. Note that when you work with local notebooks, yous don't need to launch any Jupyter server in advance: only execute any cell and the server will be launched.
Run code cells
-
Utilise the following smart shortcuts to quickly run the code cells:
-
Ctrl+Enter: Runs the current prison cell.
-
Shift+Enter: Runs the current cell and select the jail cell below it.
When executing ane cell at a time, heed lawmaking dependencies. If a jail cell relies on some code in another prison cell, that cell should be executed first.
In case of any errors, expand the Traceback node to preview the consummate error message.
-
-
To execute all lawmaking cells in your notebook, click on the notebook toolbar or printing Ctrl + Shift + Alt + Enter .
When you terminate the server and change the server or kernel, you lot have to execute all cells with dependencies again, because execution results are valid for the electric current server session simply.
View variables
-
When you execute your notebook, you can preview variables in the Variables tab of the Jupyter tool window.
By default, variables are loaded asynchronously. To change the loading policy, click in the Variables tab, select Variables Loading Policy, and select i of the available modes. Come across Managing Variables Loading Policy for more than details.
Yous can click the link to the right of the variable to preview its values in the tabular course.
In addition to previewing values of the variables in the Variables tab, you tin watch the values of the variable usages in the editor. Annotation that variable assignments are not shown.
To enable this pick, select Show inline values in the editor in project .
Once you lot've executed the cell, its output is shown below the code. You tin save the results or articulate the output.
Process output
-
If your notebook cell involves whatever code that plots charts, y'all tin can salvage the chart as an image: correct-click the output and select Salvage As from the context menu.
You lot can capsize the plotted epitome for amend readability. Select the Capsize images in night themes checkbox on the Jupyter folio in the project Settings/Preferences (Ctrl+Alt+S) and restart the editor to use the changes.
-
When any data frames are congenital, y'all can preview them in the tabular form. To open a information frame in an editor tab, correct-click the cell output and select menu item.
You can copy the selected fragment or all cells of the table. To save the output in the *.csv format, select the carte particular course the context menu and specify a filename. By default, the tabular array is saved in output.csv.
You can sort data in a cavalcade by clicking its header. You can also re-create a column header or all headers of the table to the clipboard. Simply correct-click any table header to become the context menu and select the target command.
-
You tin can manage the length of the notebook by expanding and collapsing jail cell outputs. Click an arrow nearby a jail cell counter to expand or plummet the jail cell output.
With PyCharm y'all tin can e'er apace preview reference documentation for a item variable, blazon, or argument.
Preview reference documentation
-
To view reference information for any element of a item code prison cell, place the caret within the target lawmaking cell and type
? <type/variable/statement>
. (in this instance, yous will preview documentation forplt.scatter
). Note that a code element should exist accessible within the code cell. -
Execute the jail cell. The Introspection tab opens in the Jupyter tool window.
-
Preview reference documentation in the Introspection tab.
Note that the Introspection tab shows documentation for the latest requested code element. Fifty-fifty though you proceed with executing other code cells, restart the server, or delete the line with your request, this information will be shown.
PyCharm provides the full-functional Jupyter Notebook Debugger.
Debug code in Jupyter notebooks
-
Gear up the breakpoints in the selected jail cell and press Alt + Shift + Enter for Windows or ⌥⇧↩ for macOS. Alternatively, you tin can right-click the cell and select from the context carte.
The Jupyter Notebook Debugger tool window opens.
-
Utilize the stepping toolbar buttons stepping toolbar to cull on which line y'all want to finish adjacent and switch to the Debugger tab to preview the variable values:
Debugging is performed within a single lawmaking prison cell. Withal, if your code cell calls a role from whatsoever cell that has been already debugged, you tin can step into it. The related breakpoints volition also work. Note that the cell with the function must be debugged non simply executed.
Similarly, you lot can step into a function called from a Python file that is located in the same projection.
-
Proceed with the debugging steps to consummate the execution of the cell.
Item | Tooltip and Shortcut | Clarification |
---|---|---|
Action available on the Debugger toolbar. | ||
| Step Over F8 | Click this button to execute the program until the adjacent line in the current method or file, skipping the methods referenced at the current execution bespeak (if any). If the electric current line is the final 1 in the method, execution steps to the line executed correct after this method. |
| Step Into F7 | Click this button to have the debugger step into the method called at the current execution point. |
| Step Out Shift+F8 | Click this button to have the debugger step out of the electric current method, to the line executed correct after it. |
Additional stepping deportment available by clicking on the Debugger toolbar. | ||
| Force Step Over | Steps over the current line of code and takes you to the next line even if the highlighted line has method calls in information technology. If there are breakpoints in the chosen methods, they are ignored. |
| Smart Footstep Into | Smart step into is helpful when in that location are several method calls on a line, and you desire to exist specific about which method to enter. This feature allows yous to select the method call you are interested in. |
| Run to Cursor Alt+F9 | Click this push to resume programme execution and intermission until the execution bespeak reaches the line at the current cursor location in the editor. No breakpoint is required. Actually, there is a temporary breakpoint set for the current line at the caret, which is removed once program execution is paused. Thus, if the caret is positioned at the line which has already been executed, the program will be just resumed for farther execution, because there is no fashion to coil dorsum to previous breakpoints. This activity is peculiarly useful when you accept stepped deep into the methods sequence and need to step out of several methods at once. If in that location are breakpoints set for the lines that should be executed before bringing yous to the specified line, the debugger will pause at the beginning encountered breakpoint. |
| Force Run to Cursor | Continues the execution until the position of the caret is reached. All breakpoints on the style are ignored. |
Last modified: xix November 2021
clelanddessitheigh78.blogspot.com
Source: https://www.jetbrains.com/help/pycharm/running-jupyter-notebook-cells.html