PyCharm 2024.3 Help

Configuring Project Structure

In PyCharm, content is a collection of files with which you are currently working, possibly organized in a hierarchy of subfolders. The top-level folder of a project is its content root.

Project structure

Within a content root, PyCharm can distinguish between the folders that contain source code, and the ones to be ignored while searching, parsing, watching and so on. To distinguish different types of folders, mark any folder below a content root as a source folder or as excluded.

  • Source roots the Source root icon contain the actual source files and resources. PyCharm uses the source roots as the starting point for resolving imports

  • Excluded roots the Excluded root icon contain files and folders ignored by PyCharm when indexing, searching, parsing, watching, and so on.

  • Test sources roots the Tests root icon These folders keep code related to testing separately from production code. Code sources and test sources are normally placed into different folders.

  • Resource roots the Resources root icon (PyCharm Professional only) are intended for resource files in your application (images, Style Sheets, and so on). By assigning a folder to this category, you tell PyCharm that files in it and in its subfolders can be referenced relative to this folder instead of specifying full paths to them.

  • Namespace package Package With namespace packages you can create the sub-packages and modules within a single package. You can mark any directory as a namespace package to resolve import statements within that directory.

  • Template roots the Template Folder icon (PyCharm Professional only) contain templates for the various web projects.

To access project structure, open Settings by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or PyCharm | Preferences for macOS, then expand the Project node, and select Project Structure.

Create a content root

  1. Open the Project Structure settings.

  2. In the Projects pane of the Project Structure page, click the project you want to configure content roots for.

  3. In the Content roots of the Project Structure page, click the Add Content Root button Add Content Root.

  4. In the dialog that opens, locate the desired directory and click OK.

    Add Content Root

Remove a content root

  1. Open the Project Structure settings.

  2. In the Projects pane of the Project Structure page, click the project you want to configure content roots for.

  3. In the Content roots pane of the Project Structure page, select the content root that you want to delete.

  4. Click the Remove button Remove content root and confirm removal.

    Remove content root

You can assign a folder to a different category. This can be done both in the Project tool window and on the Project Structure page of the Settings dialog.

Assign a category to a folder in the Project tool window

  1. Open the Project tool window (for example View | Tool Windows | Project).

  2. Select the folder that you want to assign to a certain category.

  3. Right-click it and select the desired category from Mark Directory As menu.

    Mark directory in the Project tool window

In a similar way you can change the folder category at a later time. (Just select a different category from the context menu.)

To cancel the folder association with its current category (that is to make a folder an "ordinary" folder Folder), select Unmark as <current_category> Root. (for example Unmark as Resource Root).

Assign a category to a folder in the project settings

  1. Open Project Structure page of the Settings dialog (Ctrl+Alt+S).

  2. Select the folder you want to assign a category to.

  3. Click the category button, for example, root_Source.png.

    Assign a category to a folder in the project settings

You can make files and folders excluded by specifying the name patterns. Use the Exclude files field to specify the patterns.

The files and folders whose names match at least one of the specified patterns are made excluded. Folders are excluded along with all their contents.

Last modified: 29 October 2024