Python console | PyCharm (2024)

Python console enables executing Python commands and scripts line by line, similar to your experience with Python Shell.

Actions available in the Python Console

In the console, you can:

  • Type commands and press Enter to execute them. Results are displayed in the same console.

  • Use basic code completion Ctrl+Space and tab completion.

  • Run asyncio coroutines.

  • Use Up and Down to scroll through the history of commands, and execute the required ones.

  • Load source code from the editor into console.

  • Use the context menu to copy the contents of the console to the clipboard, compare it with the clipboard, or clear the console.

  • Use the toolbar buttons to control your session in the console.

  • Configure color scheme of the console to meet your preferences. For more information, refer to Configure color schemes for consoles.

  • Use config files to configure the IPython console automatically.

Working with Python console

The console appears as a tool window every time you choose the corresponding command on the Tools menu. You can assign a shortcut to open Python console: press Ctrl+Alt+S, navigate to Keymap, specify a shortcut for Main menu | Tools | Python or Debug Console.

The main reason for using the Python console within PyCharm is to benefit from the main IDE features, such as code completion, code analysis, and quick fixes.

Python console | PyCharm (1)

You can use up and down arrow keys to browse through the history of executed commands, and repeat the desired ones. To preview the variable values calculated in the course of the execution, click Python console | PyCharm (2) and check the Special Variables list.

Python console | PyCharm (3)

The console is available for all types of Python interpreters and virtual environments, both local and remote.

View data structures

  • When viewing variables in the Python Console, you can click View as Array, View as DataFrame, or View as Series links to display the data in the Data View tool window.

    Python console | PyCharm (4)
  • By default, the new table representation is used. Click Python console | PyCharm (5) Switch Between Table Representations to change the table interface.

  • Click Table Coloring Options to toggle and configure cell coloring.

    Python console | PyCharm (6)
  • Use the Format field to adjust the data frame formatting.

    Python console | PyCharm (7)

Run source code from the editor in console

  1. Open file in the editor, and select a fragment of code to be executed.

  2. From the context menu of the selection, choose Execute Selection in Python Console, or press Alt+Shift+E:

    Python console | PyCharm (8)
  3. Watch the code selection execution:

    Python console | PyCharm (9)

By default, the Python console executes Python commands using the Python interpreter defined for the project. However, you can assign an alternative Python interpreter.

Run asyncio coroutines

  1. In the editor, select a fragment of code which contains the definition of an asyncio coroutine.

  2. From the context menu, select Execute Selection in Python Console, or press Alt+Shift+E:

    Python console | PyCharm (10)
  3. After the code is executed on the Python console, run the coroutine by using the await keyword:

    Python console | PyCharm (11)

Configure Python console settings

  1. In the Settings dialog (Ctrl+Alt+S) , select Build, Execution, Deployment | Console | Python Console.

  2. Select any available interpreter from the Python interpreter list. Note that you cannot introduce a new interpreter here. If you want to come up with the new interpreter, you need to create it first.

    Python console | PyCharm (12)
  3. In needed, click the Configure Interpreters link to inspect the list of the installed packages and add new ones.

    Mind the code in the Starting script area. It contains the script that will be executed after you open the Python console. Use it to pre-code some required Python commands.

When working on several Python scripts, you might want to execute each in a separate Python console.

Run several Python consoles

  1. Click Python console | PyCharm (13) to add a new Python console.

  2. By default, each console has the name Python Console with an index. To make a console reflect the script you're running, right-click the console tab, select Rename Console, and enter any meaningful name.

    Python console | PyCharm (14)

All the commands you're running in the Python console are executed one by one. If the commands require substantial time to get executed, you might want to preview and manage the execution queue.

Manage the command execution queue

  1. Go to Settings | Build, Execution, Deployment | Console and enable the Command queue for Python Console checkbox.

  2. Click Python console | PyCharm (15) on the console toolbar to open the queue.

    Python console | PyCharm (16)
  3. In the Python Console Command Queue dialog, review the list of commands. If needed, click Python console | PyCharm (17) to delete the command from the queue.

Note, once the command is executed, it disappears from the queue. To preview all previously executed commands browse the console history (Python console | PyCharm (18)).

Toolbar

Item

Tooltip and shortcut

Description

Python console | PyCharm (19)

Rerun console

Ctrl+F5

Click this button to terminate the current process and launch the new one.

Python console | PyCharm (20)

Stop

Ctrl+F2

Click this button to stop the current process.

Clicking the button once invokes soft kill allowing the application to catch the SIGINT event and perform graceful termination (on Windows, the Ctrl+C event is emulated) . After the button is clicked once, it is replaced with Python console | PyCharm (21) indicating that subsequent click will lead to force termination of the application, for example on Unix SIGKILL is sent.

Python console | PyCharm (22)

Execute Current Statement

Enter.

Click this button to execute the command at caret, entered in the input pane of the console.

Python console | PyCharm (23)

Attach Debugger

Attaches the debugger process to the console.

Python console | PyCharm (24)

Settings

You can specify the following settings of the Python console:

  • Simplified Variables View: Select this option to include the following names into the Special Variables group:

    • all variables with the dunder names.

    • all instances of function, classobj and module.

    • all the IPython internal variables, if debug console with IPython has been started.

  • Variables Loading Policy. You can choose one of the following policies:

    • Synchronously: If this option is enabled, the message shown is Collecting data, and after that the debugger shows the variables' values.

    • Asynchronously: If this option is enabled, the variables in the debugger are loaded separately (asynchronously). In this case, if loading a variable takes a long time, the debugger shows ...Loading Value message, and only after that it shows its value or the Loading timed out message, if the variable is too slow. Mind the warning message that suggest switching to the on demand mode.

    • On demand: If this option is enabled, the debugger shows Show Value message. Click it to enable loading.

    Note that any changes in the loading policies become effective after you rerun the debugging process.

Python console | PyCharm (25)

New Console

Click this button to start a new console session.

Python console | PyCharm (26)

Use Soft Wraps

Click this button to toggle the soft wrap mode of the output.

Python console | PyCharm (27)

Scroll to the end

Click this button to navigate to the bottom of the stack trace and have the caret jump to the corresponding location in the source code.

Python console | PyCharm (28)

Print

Click this button to send the console text to the default printer.

Python console | PyCharm (29)

Show variables

Click this button to show in a separate pane the variables declared in the console. Right-click a variable in this pane reveals a context menu.

Python console | PyCharm (30)

Show Command Queue

Click this button to preview the command execution queue.

Python console | PyCharm (31)

Browse History

Ctrl+Alt+E

Open a dialog that shows all the statements that you have run for the corresponding data source.

See also, Use the Query History dialog.

Context menu commands

Command

Shortcut

Description

Python console | PyCharm (32) Compare with Clipboard

Show selection in the console and contents of the Clipboard in the Diff Viewer.

Pause Output

Pause the Python script execution output

Python console | PyCharm (33) Clear All

Choose this item from the context menu to delete all messages from the upper part of the console.

Last modified: 15 February 2024

Work with consolesTerminal emulator

Python console | PyCharm (2024)
Top Articles
The Importance of Excel in Business
Agent, Broker, Realtor: What’s the Difference?
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 5895

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.