PyCharm 2022.2 Help

Shared indexes

One of the possible ways of reducing the indexing time is by using shared indexes. Unlike the regular indexes that are built locally, shared indexes are generated once and are later reused on another computer whenever they are needed.

PyCharm can build shared indexes for your project's code. Whenever PyCharm needs to reindex your application, it will use the available shared indexes and will build local indexes for the rest of the project. Normally, this is faster than building local indexes for the entire application from scratch.

Make sure the plugin is installed

To be able to use shared project indexes, the Shared Project Indexes bundled plugin must be enabled in the settings:

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Plugins.

  2. Switch to the Installed tab, type Shared Project Indexes, and make sure that the checkbox next to it is selected.

    Otherwise, select the checkbox to enable the plugin.

  3. Apply the changes and close the dialog. Restart the IDE if prompted.

When you launch a project, PyCharm processes local and shared indexes together at the same time. This might increase CPU usage on your computer. If you want to avoid this, enable the Wait for shared indexes option in Settings/Preferences | Tools | Shared Indexes.

Shared indexes for Python packages

PyCharm can help you download pre-built shared indexes for Python packages. When you open a project, it shows a notification prompting you to enable the automatic download.

Shared indexes

If you miss the notification, you can configure these options in the settings.

  1. In the Settings/Preferences dialog, select Tools | Shared Indexes.

    Settings: Shared Indexes
  2. Select the Download automatically option for Python packages to allow PyCharm to download the indexes silently whenever they are needed.

    Alternatively, select Ask before download if you prefer to confirm every download manually.

Python packages indexes will be downloaded to index/shared_indexes in the IDE system directory.

Shared project indexes

Shared project indexes are built for all project sources, libraries, and SDKs. You can generate them on one computer and then apply on another computer. This is the main advantage of shared indexes over ordinary indexes.

Using shared indexes is reasonable for large projects, where indexing might take a lot of time, creating inconveniences for the teams involved. For smaller projects, we recommend other ways of reducing the indexing time.

Before you begin

  • To ensure index compatibility, use the same IDE version on the source and the target computer.

  • You can have different operating systems on the source and the target computer.

    However, in previous PyCharm versions, project shared indexes were OS-specific. Refer to the documentation that corresponds to your IDE version by using the version switcher in the top-left corner of this page.

Share project indexes from the command line

In order to share project indexes, install a command line tool and prepare the IDE. By doing so, you're making sure that no caches or other internal files interfere with the information that you are going to export from your project.

When the indexes and related metadata are exported, upload them to your file storage. Other members of your team can then configure their IDEs to automatically connect to that storage and download the indexes whenever they are needed.

Prepare a file storage

Sharing indexes from the command line requires that you have a file storage that will keep the exported project indexes.

  • Make sure that you have a file storage ready, and all members of your team have access to this storage.

Install cdn-layout-tool

To be able to export and share project indexes, install cdn-layout-tool – a JetBrains tool for working with shared project indexes:

  1. Download the latest version of the tool from the Space repository.

  2. Once the .zip file is downloaded, extract its contents to a meaningful location.

    Among the .zip file's content, there's a bin directory. There, you will find an OS-specific startup script that you will need later for generating metadata.

Prepare the IDE for sharing project indexes

  1. Create the following directories or remove the contents from the existing ones:

    • <temp>/ide-system

    • <temp>/ide-config

    • <temp>/ide-log

    Note that in different operating systems, the temp directory has a different location.

  2. Copy the <IDE home>/bin/idea.properties file to the <temp> directory. For more information on idea.properties, refer to Common properties.

  3. Rename idea.properties to ide.properties in <temp>.

  4. Change the following properties in the <temp>/ide.properties file :

    • idea.system.path=<temp>/ide-system

    • idea.config.path=<temp>/ide-config

    • idea.log.path=<temp>/ide-log

    If you don't have these properties in the file, add them at the end.

  5. Set a temporary environment variable to specify the custom IDE properties file. To do so, run the following command:

    set PYCHARM_PROPERTIES=<temp>\ide.properties
    export PYCHARM_PROPERTIES=<temp>/ide.properties

Export project indexes

  1. Make sure that the <temp>/generate-output directory is empty. If there's no such directory, do not create it as this will be done automatically during the export.

  2. Run the IDE with the following command line to export the project indexes to <temp>/generate-output.

    <IDE command-line launcher> dump-shared-index project --output=<temp>/generate-output --tmp=<temp>/temp --project-dir=<path> --project-id=<project-name> --commit=<Git HEAD>

    You can find the executable for running PyCharm in the installation directory under bin. To use this executable as the command-line launcher, add it to your system PATH as described in Command-line interface.

    Syntax
    pycharm.bat dump-shared-index project --output=<temp>/generate-output --tmp=<temp>/temp --project-dir=<path> --project-id=<project-name> --commit=<Git HEAD>
    Options

    --output=<temp>/generate-output

    Output location for the generated shared indexes in the <temp> folder.

    --tmp=<temp>/temp

    The temp directory used for the internal needs of the IDE.

    --project-dir=<path>

    The path to the project for which you want to export indexes.

    --project-id=<id>

    The name of the project.

    --commit=<vcs revision>

    The VCS revision identifier (for example, Git commit hash) representing the state of the project for which the shared index is being generated.

    This is needed to lay out the shared indexes of several VCS revisions in the file storage.

    This identifier is optional. If it is not specified, it will be set to -.

    --compression=<compression type>

    Compress shared indexes. Possible options: xz, gzip, and plain.

    By default, PyCharm does not provide a command-line launcher. For information about creating a launcher script for PyCharm, see Command-line interface.

    Syntax
    pycharm dump-shared-index project --output=<temp>/generate-output --tmp=<temp>/temp --project-dir=<path> --project-id=<project-name> --commit=<Git HEAD>
    Options

    --output=<temp>/generate-output

    Output location for the generated shared indexes in the <temp> folder.

    --tmp=<temp>/temp

    The temp directory used for the internal needs of the IDE.

    --project-dir=<path>

    The path to the project for which you want to export indexes.

    --project-id=<id>

    The name of the project.

    --commit=<vcs revision>

    The VCS revision identifier (for example, Git commit hash) representing the state of the project for which the shared index is being generated.

    This is needed to lay out the shared indexes of several VCS revisions in the file storage.

    This identifier is optional. If it is not specified, it will be set to -.

    --compression=<compression type>

    Compress shared indexes. Possible options: xz, gzip, and plain.

    You can find the script for running PyCharm in the installation directory under bin. To use this script as the command-line launcher, add it to your system PATH as described in Command-line interface.

    Syntax
    pycharm.sh dump-shared-index project --output=<temp>/generate-output --tmp=<temp>/temp --project-dir=<project> --project-id=<project-name> --commit=<Git HEAD>
    Options

    --output=<temp>/generate-output

    Output location for the generated shared indexes in the <temp> folder.

    --tmp=<temp>/temp

    The temp directory used for the internal needs of the IDE.

    --project-dir=<path>

    The path to the project for which you want to export indexes.

    --project-id=<id>

    The name of the project.

    --commit=<vcs revision>

    The VCS revision identifier (for example, Git commit hash) representing the state of the project for which the shared index is being generated.

    This is needed to lay out the shared indexes of several VCS revisions in the file storage.

    This identifier is optional. If it is not specified, it will be set to -.

    --compression=<compression type>

    Compress shared indexes. Possible options: xz, gzip, and plain.

    The export might take some time. When the process is finished, the following files are placed to <temp>/generate-output:

    • shared-index-project-<name>-<hash>.ijx.xz

    • shared-index-project-<name>-<hash>.metadata.json

    • shared-index-project-<name>-<hash>.sha256

Copy the generated files to a new folder

  1. Create a new directory <temp>/indexes and download there all the contents of your remote file storage.

    You can create the new directory inside the directory that has <temp>/generate-output subdirectory. This can be any directory, for example ~/indexes/project/<project name>/<VCS hash>/share.

  2. Copy the generated files (.ijx.xz, .metadata.json, .sha256) from <temp>/generate-output to a subdirectory of <temp>/indexes.

    This can be any folder, for example <temp>/indexes/project/<project name>/<VCS hash>/<indexes>.

Generate metadata

  • Generate auxiliary files used by the IDE to look up for and download shared indexes. To do so, run cdn-layout-tool with the following command line.

    <cdn-layout-tool> --indexes-dir=<dir> --url=<file storage root URL>
    Options

    <cdn-layout-tool>

    The path to cdn-layout-tool startup script located in bin in the tool directory.

    --indexes-dir=<dir>

    The directory containing all the files available in the file storage, as well as the newly generated shared indexes residing in a suitable location beneath this directory.

    The tool will generate the missing files and replace existing ones if necessary. After the tool has finished running, all the contents of this directory must be uploaded to the file storage. This will set the new state of the storage.

    --url=<file storage root URL>

    The base URL of the file storage root directory. cdn-layout-tool will substitute the download URL in all the corresponding .json index lists.

    Example
    /Users/User/Desktop/cdn-layout-tool-0.7.52/bin/cdn-layout-tool --indexes-dir=/var/folders/dr/xxx_x00x0x0_x0xx000xx000000xx/T/indexes --url=https://my-file-storage.com/intellij-indexes

Upload the index files to your file storage

  • Upload all the files from <temp>/indexes to the file storage as is.

    If there are already uploaded index files in the storage, update them.

Download indexes from the file storage

Once the project indexes are uploaded to the file storage, they can be downloaded and applied on another computer.

  1. In the project directory, create a new file intellij.yaml and add the following code:

    sharedIndex: project: - url: <feed URL>

    Replace <feed URL> with the URL of your file storage in the following format: <file storage root URL>/project/<project-id>.

  2. In the Settings/Preferences dialog (Ctrl+Alt+S), select Tools | Shared Indexes.

  3. In the Project Shared Indexes area, select the way you want to download shared indexes from the storage.

    Select Download automatically to allow PyCharm to download the JDK indexes silently whenever they are needed or select Ask before download if you prefer to confirm every download manually.

    Configuring options for downloading shared indexes
  4. Apply the changes and close the dialog.

Project indexes will be downloaded to index/shared_indexes in the IDE system directory.

Remove the downloaded shared indexes

If you don't need the project indexes anymore (for example, if the project is no longer in development), you can remove them all together. In this case, the IDE will remove the regular indexes and all the downloaded shared indexes for the project and the JDK.

  1. From the main menu, select File | Invalidate Caches.

  2. In the dialog that opens, select Clear downloaded shared indexes and click Invalidate and Restart.

Last modified: 27 September 2022