Pycharm python console settings

Console. Python Console

Use this page to define the Python interpreter, its options, starting script and so on for the Python console.

This field shows the list of environment variables. If the list contains several variables, they are delimited with semicolons.

To fill in the list, click the browse button, or press Shift+Enter and specify the desired set of environment variables in the Environment Variables dialog.

To create a new variable, click , and type the desired name and value.

You might want to populate the list with the variables stored as a series of records in a text file, for example:

Just copy the list of variables from the text file and click Paste () in the Environmental Variables dialog. The variables will be added to the table. Click Ok to complete the task. At any time, you can select all variables in the Environment Variables dialog, click Copy , and paste them into a text file.

Select one of the pre-configured Python interpreters from the list.

Читайте также:  This html is simple

In this field, specify the string to be passed to the interpreter. If necessary, click Enter , and type the string in the editor.

Specify a directory to be used by the running console. When this field is left blank, the project directory will be used.

This field is only available for remote interpreters.

the Browse button

This field shows mappings between the desired local path and the corresponding remote path. PyCharm allows configuring paths by clicking next to the field. In the dialog that opens, click or buttons to change the path mappings as desired.

If the desired interpreter is missing in the list, click this link to open the Python Interpreters page, and configure an interpreter or virtual environment , as described in the section Configuring Python SDK.

Add content roots to PYTHONPATH

Select this checkbox to have the content roots added to the PYTHONPATH.

Add source roots to PYTHONPATH

Select this checkbox to have the source roots added to the PYTHONPATH.

Starting script

In this editor area, type the script to be executed in the console after its start-up and initialization. Note that syntax highlighting, code completion, import assistance, documentation, inspections and quick fixes are available in this editor:

By default, this area contains the following script, which causes printing out a header information and extending the system paths:

import sys; print(‘Python %s on %s’ % (sys.version, sys.platform)) sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])

The WORKING_DIR_AND_PYTHON_PATHS variable is hardcoded in PyCharm. It displays two paths: the project root and the working directory. The project root is the top-level directory of your project. The working directory may coincidence with the project root if not explicitly defined in the Working directory field.

If you want to omit such a printout, delete this script.

Источник

Python console

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

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 Control+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.

Code completion in the Python console

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 and check the Special Variables list.

Show variables in the Python console

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

Preview a variable as an array

When your variables are numpy arrays or dataframes, you can preview them as an array in a separate window. To try it, do one of the following:

  • Click the link View as Array / View as DataFrame : Viewing variables in array when running from Python console
  • From the context menu of a variable, choose View as Array / View as DataFrame : Viewing variables in data frames when running from Python console

The variable will be opened in the Data tab of the SciView window.

View an array or dataframe in a separate window

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 : Context menu for executing the code selectionWith no selection, the command changes to Execute line in console . Choose this command from the context menu, or press Alt+Shift+E . The line at caret loads into the Python console, and runs.
  3. Watch the code selection execution: Execution of the code selection in the console

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 : Selecting and executing asyncio coroutines in the Python console
  3. After the code is executed on the Python console, run the coroutine by using the await keyword: Execution of the asyncio coroutine in the console

Configure Python console settings

Search an alternative Python interpreter

  1. In the Settings dialog ( Control+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.
  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

Rename the Python console

  1. Click 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.

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

Console command queue

  1. Go to Settings | Build, Execution, Deployment | Console and enable the Command queue for Python Console checkbox.
  2. Click on the console toolbar to open the queue.
  3. In the Python Console Command Queue dialog, review the list of commands. If needed, click 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

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

Actions available in the Python Console

  • Type commands and press Enter to execute them. Results are displayed in the same console.
  • Use basic code completion Control+Space and tab completion.
  • Use the await keyword to run asyncio coroutines.
  • Use Up and Down arrow keys 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. Refer to the section Configure color schemes for consoles for details.

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 Control+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.

Code completion in the Python console

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 and check the Special Variables list.

Show variables in the Python console

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

Preview a variable as an array

When your variables are numpy arrays or dataframes, you can preview them as an array in a separate window. To try it, do one of the following:

  • Click the link View as Array / View as DataFrame : Viewing variables in array when running from Python console
  • From the context menu of a variable, choose View as Array / View as DataFrame : Viewing variables in data frames when running from Python console

The variable will be opened in the Data tab of the SciView window.

View an array or dataframe in a separate window

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 : Context menu for executing the code selectionWith no selection, the command changes to Execute line in console . Choose this command from the context menu, or press Alt+Shift+E . The line at caret loads into the Python console, and runs.
  3. Watch the code selection execution: Execution of the code selection in the console

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 : Selecting and executing asyncio coroutines in the Python console
  3. After the code is executed on the Python console, run the coroutine by using the await keyword: Execution of the asyncio coroutine in the console

Configure Python console settings

Search an alternative Python interpreter

  1. In the Settings dialog ( Control+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.
  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

Rename the Python console

  1. Click 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.

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

Console command queue

  1. Go to Settings | Build, Execution, Deployment | Console and enable the Command queue for Python Console checkbox.
  2. Click on the console toolbar to open the queue.
  3. In the Python Console Command Queue dialog, review the list of commands. If needed, click 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 ().

Источник

Work with consoles

PyCharm enables you to use interactive consoles, thus making it possible to stay within the IDE, without the necessity to switch to the shell.

Show variables in the Python console

Launch a console

  • From the main menu, choose any console-related command from the Tools menu, for example, Python or Debug console . Alternatively, select the corresponding window in the tool windows group underneath the editor.

When the current project is a Django project, the console that starts is Django Console . However, if the current project is pure Python project, then PyCharm starts Python Console .

PyCharm creates files using the IDE encoding defined in the File Encodings page of the Settings dialog Control+Alt+S . You can use either the system default or select from the list of available encodings. By default, this encoding affects console output. If you want the encoding for console output to be different from the global IDE settings, configure the corresponding JVM option:

Configure output encoding

  1. On the Help menu, click Edit Custom VM Options .
  2. Add the -Dconsole.encoding option and set the value to the necessary encoding. For example: -Dconsole.encoding=UTF-8
  3. Restart PyCharm.

Configure console colors

  1. Make sure you are working with an editable scheme.
  2. In the Settings dialog ( Control+Alt+S ), go to Editor | Color Scheme , and select the setting pages related to consoles:
    • Console Colors
    • Console Font
  3. In the right-hand pane, select the desired component in the list, and change its color settings and font:

Источник

Оцените статью