Перейти к содержимому

Как установить python в intellij idea

  • автор:

Python language support

The following is only valid when the Python plugin is installed and enabled.

To develop Python scripts in IntelliJ IDEA:

  • Download and install Python.
  • Configure at least one Python SDK.

If you are a Windows user, we recommend that you install Python for Windows.

Supported versions

  • Python 2: version 2.7
  • Python 3: from the version 3.6 up to the version 3.12
  • PEP 647 – User-Defined Type Guards
  • PEP 604 – Allow writing union types as X | Y
  • PEP 612 – Parameter Specification Variables
  • PEP 613 – Explicit Type Aliases
  • PEP 634 – Structural Pattern Matching: Specification
  • PEP 635 – Structural Pattern Matching: Motivation and Rationale
  • PEP 636 – Structural Pattern Matching: Tutorial
  • PEP 585 – Type Hinting Generics In Standard Collections
  • PEP 593 – Flexible function and variable annotations
  • PEP 614 – Relaxing Grammar Restrictions On Decorators
  • PEP-570 – Python Positional-Only Parameters
  • PEP-572 – Assignment Expressions
  • PEP-586 – Literal Types
  • PEP-589 – TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys
  • PEP-591 – Adding a final qualifier to typing
  • Python bug tracker task #36817 – Support = expressions in f-strings

Python support in IntelliJ IDEA

IntelliJ IDEA provides the following features to help you work with Python:

  • Dedicated module type.
  • Ability to configure interpreters. .
  • Python console .
  • Run/debug configurations for Python, and Python remote debug.
  • Code insight
  • Code inspections.
  • Intention actions.
  • Code completion and resolve.
  • Built-in code formatter and separate set of Python code style settings.
  • Find usages in Python code.
  • Testing frameworks.
  • Quick documentation.
  • Recognizing Python documentation comments .
  • Configuring Python debugger.
  • UML Class diagram for Python classes.

Python

The following is only valid when the Python plugin is installed and enabled.

Python Plugin extends IntelliJ IDEA with the full-scale functionality for Python development.

Prerequisites

Before you start working with Python, make sure that Python plugin is installed and enabled. Press Control+Alt+S , go to Plugins and inspect the Installed tab to ensure the plugin is enabled.

Also make sure that the following prerequisites are met:

  • Python SDK is downloaded and installed on your machine.
  • The required framework SDKs are downloaded and installed on your machine.

For more information, refer to their respective download and installation pages:

Changes to the UI

Being installed, the Python Plugin introduces the following changes to the IntelliJ IDEA UI:

  • Python module type is added to the New Project and New Module wizards. Creating a new Python project
  • Python file type is added to the File | New menu. The Python file, Python unit test, and Python stub file types are available. Creating a new Python file
  • Python SDK can be specified in the Add new SDK popup under the SDKs node of the Project Structure dialog. Adding a Python SDK
  • Django and Google App Engine (Python) are implemented as the facets, which can be attached to a Python module, either in the New Project dialog, or in the Modules or facets pages of the Project Structure dialog:

facets

modules

Python-related options in the Tools menu

  • Python-related commands are added to the Tools menu:
  • Python and framework-specific run/debug configurations, inspections, intention actions, and refactorings.
  • Besides that, the following changes are made to the Settings dialog:

    • Python code style, colors and fonts, live templates.
    • Python Debugger is added under the Build, Execution, Deployment node.
    • Python-related options add to the Stepping page.
    • Python console pages are added.
    • Syntax and error highlighting
    • More Python-specific options are added to the Coverage page.
    • Python Template Languages , Python External Documentation, Python Integrated Tools, and Python Scientific pages are added.
    • The Scientific Mode option is added to the View menu.

    Install, uninstall, and upgrade Python packages

    The following is only valid when the Python plugin is installed and enabled.

    IntelliJ IDEA provides methods for installing, uninstalling, and upgrading Python packages for a particular Python SDK. It means that each project has its own set of packages, which is considered a best practice for Python dependency management. By default, IntelliJ IDEA uses pip to manage project packages. For conda environments you can use the conda package manager.

    In IntelliJ IDEA, you can preview and manage packages in the Python Packages tool window and in the Python interpreter settings.

    Manage packages in the Python Packages tool window

    The Python Packages tool window provides the quickest and neat way to preview and install packages for the currently selected Python interpreter. This tool window is enabled by default, and you can open it by clicking Python Packages on the left. At any time you can open it using the main menu: View | Tool Windows | Python Packages .

    The Python Packages tool window shows installed packages and the packages available in the PyPI and conda package repositories. Use the search field to filter the list of the available packages.

    Python Packages tool window

    You can preview the package documentation in the documentation area, or click the Documentation link and open it in a browser.

    Install packages

    1. Start typing the package name in the search field of the Python Packages tool window. The matching packages are displayed. Search for the package in the Python Packages tool windowIf the current Python interpreter is a conda virtual environment, the packages available in the conda package repository are also displayed.
    2. Select the package and then do one of the following:
      • Click Install next to the package name and choose the version. Installing the package from the search results
      • Expand the list of the available versions and select the version. Then click the Install with pip button.

      Selecting the package version to be installed

    3. If a popup with an error message appears, refer to the Troubleshooting guide for a solution.

    Manage package repositories

    1. To specify a custom repository, for example devpi or a private PyPi server, click Settings next to the search field.
    2. In the Python Packages Repositories dialog, click Add . If no authorization is required, for example, in the case of a local repository, type the repository URL and click OK . Adding a Python repository: No Authorization
    3. If you want to install Python packages from a repository that requires HTTP authorization, click Basic HTTP and type the repository URL and the login credentials. Click OK to complete the task. Adding a Python repository: Basic HTTP Authorization

    Install packages from Version Control System

    Install from Version Control

    1. Click the Add Package link on the Python Packages toolbar and select From Version Control .
    2. Specify a path to the target git repository. For more information about supported path formats, refer to pip documentation.
    3. Select Install as editable (-e) if you want to install the package in the editable mode (for example, setuptools develop mode ).

    Install packages from disk

    Install package from disc

    1. Click the Add Package link on the Python Packages toolbar and select From Disk .
    2. Specify a path to the package directory or an archive ( zip or whl ).
    3. Select Install as editable (-e) if you want to install the package in the editable mode (for example, setuptools develop mode ).

    Upgrade packages

    A newer version of the package is available

    • If a newer version of the package is available, a link with the current version and the newest version is displayed next to the package name. Click the link to upgrade the package to the latest version. If a popup with an error message appears, refer to the Troubleshooting guide for a solution.

    Uninstall packages

    Uninstalling a package in the Python Packages tool window

    • To delete an installed package, click More next to the package version and select Delete Package .

    Manage packages in Python interpreter settings

    To manage Python packages for a project Python interpreter, go to File | Project Structure in the main menu, select SDKs under the Platform Settings section, and select the target Python SDK from the list of the available SDKs. Switch to the Packages tab to preview the list of the available packages.

    Installing a Python package

    Install packages

    1. Click the Install on the toolbar. Add a package
    2. In the Available Packages dialog that opens, type the name of the package in the search field. Show available packages
    3. If required, select the following checkboxes:
      • Specify version : if this checkbox is selected, you can select the desired version from the list. By default, the latest version is installed.
      • Options : If this checkbox is selected, you can type the pip install command-line options in the text field.
      • Install to user’s site packages directory : If this checkbox is disabled (by default), the package will be installed into package directory of the current interpreter. If the checkbox is enabled, the package will be installed into the mentioned directory. This option is available only for conda environments.
    4. Select the package and click Install Package .
    5. If a popup with an error message appears, refer to the Troubleshooting guide for a solution.

    Install packages from conda package repository

    Using the Conda package manager

    • If you select a Python SDK with the configured conda environment, the Use Conda Package Manager toggle appears in the Packages tab toolbar. Use this toggle to install and upgrade packages from the conda package repository. This toggle is enabled by default for conda environments.

    IntelliJ IDEA provides a quick fix that automatically installs the package you’re trying to import: if, after the keyword import , you type a name of a package that is not currently available on your machine, a quick fix suggests to either ignore the unresolved reference, or download and install the missing package:

    Py import inspection

    Uninstall packages

    Uninstalling a Python package

    1. In the Packages tab , select the packages to be uninstalled.
    2. Click Uninstall on the toolbar.

    IntelliJ IDEA tracks the status of packages and recognizes outdated versions by showing the currently installed package version (column Version ), and the latest available version (column Latest version ). When a newer version of a package is detected, IntelliJ IDEA marks it with the Upgrade icon.

    By default, the Latest version column shows only stable versions of the packages. If you want to extend the scope of the latest available versions to any pre-release versions (such as beta or release candidate ), click Show early releases .

    Show latest available versions including beta and release candidates

    Upgrade packages

    Upgrading Python packages

    1. In the Packages tab , select the package to be upgraded.
    2. Click Upgrade on the toolbar. The selected package will be upgraded to the latest available version.
    3. Click OK to complete upgrading.

    You can upgrade several packages at once. Hold Cmd (macOS) or Ctrl on (Unix or Windows), left-click to select several items in the list of packages, and then click Upgrade .

    If you’re accustomed to installing packages from the command line, you can proceed with your workflow using the Terminal.

    Configure a system interpreter

    The following is only valid when the Python plugin is installed and enabled.

    To work with your Python code in IntelliJ IDEA, you need to configure at least one interpreter. A system interpreter is the one that comes with your Python installation. You can use it solely for all Python scripts or take it as a base interpreter for Python virtual environments.

    Configure a system interpreter

    1. Ensure that you have downloaded and installed Python on your computer. Installing Python on Windows from Microsoft Store If you are on Windows, you can download Python from the Microsoft Store and install it as a Python interpreter. Once the Python application is downloaded from the Microsoft Store, it becomes available in the list of the Python executables. Note that interpreters added from the Microsoft Store installations come with some limitations. Because of restrictions on Microsoft Store apps, Python scripts may not have full write access to shared locations such as TEMP and the registry.
    2. Navigate to File | Project Structure or press Control+Alt+Shift+S .
    3. In the Project Structure dialog, select SDKs under the Platform Settings section, click , and choose Add Python SDK from the popup menu. Adding a new Python SDK
    4. In the left-hand pane of the Add Python Interpreter dialog, select System Interpreter . Adding a system interpreter
    5. In the Interpreter drop-down, select one of the Python interpreters that have been installed in your system, or click and in the Select Python Interpreter dialog that opens, choose the desired Python executable. Selecting the Python executableYou will need admin privileges to install, remove, and upgrade packages for the system interpreter. When attempting to install an interpreter package through an intention action, you might receive the following error message: System Interpreter warning messageAs prompted, consider using a virtual environment for your project.
    6. Click OK to complete the task.

    For any of the configured Python interpreters (but Docker-based), you can:

    • Manage interpreter paths
    • Install, uninstall, and upgrade Python packages

    Добавить комментарий

    Ваш адрес email не будет опубликован. Обязательные поля помечены *