This feature is only supported in the Professional edition.
In PyCharm, a library is a file or a set of files whose functions and methods are added to PyCharm's internal knowledge in addition to the functions and methods that PyCharm retrieves from the project code that you edit. In the scope of a project, its libraries by default are write-protected.
PyCharm uses libraries only to enhance coding assistance (that is, code completion, syntax highlighting, navigation, and documentation lookup). Please note that a library is not a way to manage your project dependencies.
Using TypeScript community stubs (TypeScript definition files)
In PyCharm, DefinitelyTyped stubs can be configured and used as libraries, which is in particular useful in the following cases:
- To improve code completion, resolve symbols for a library or a framework that is too sophisticated for PyCharm static analysis, and add the type information for such symbols.
- To resolve globally defined symbols from test frameworks.
post()function is not resolved: PyCharm successfully resolves
To download TypeScript definitions for a library or a framework
Place the cursor at the
- Click Download on the toolbar. The Download Library dialog opens.
- Choose TypeScript community stubs from the drop-down list, select the required library, and click Download and Install. PyCharm downloads the type definitions for the selected library and shows them in the External Libraries node in the Project view.
PyCharm enables the downloaded type definitions in the scope of the current project. You can change this scope as described in Configuring the scope of a library below. See also Example: Configuring the scope for HTML and Node.js Core libraries.
Configuring Node.js Core library
To configure Node.js Core
- In the Settings/Preferences dialog (Ctrl+Alt+S), click Node.js and NPM under Languages and Frameworks. The Node.js and NPM page opens.
- In the Coding Assistance area, click Enable next to the message Node.js Core library is not enabled.
Please note that the Node.js Core library is version-specific. If you change the version of your Node.js on the Node.js and NPM page, you need to click Enable again. After that PyCharm creates a new library for this new version.
Configuring node_modules library
To provide code completion for project dependencies, PyCharm creates a
node_modules library automatically so Node.js modules are kept in your project but no inspections are run against them, which improves performance. In the Project tool window, the
node_modules is also marked as a library: However, the
node_modules library contains only the modules that are listed in the
dependencies object of your project
package.json file. PyCharm does not include the dependencies of dependencies into the
node_modules library but actually excludes them from the project.
Configuring the scope of a library
From time to time you may notice that PyCharm suggests irrelevant completion, for example, Node.js APIs in your client-side code. This happens because by default PyCharm uses a library for completion in the entire project folder. PyCharm lets you tune code completion by configuring scopes for libraries.
The scope of a library is a set of files and folders in which the library is enabled so its methods and functions are resolved and shown in completion lists.
To configure the scope of a library
- For each added file or a folder, from the Library list, select the library which you are configuring.
Example: Configuring the scope for HTML and Node.js Core libraries
- Clear the Enabled checkboxes next to HTML and Node.js Core items.
- To configure the scope for the HTML library, click , select the folders with the client-side code, and then choose HTML from the Library drop-down list.
- To configure the scope for the Node.js Core library, click again, select the folders with the server-side code, and choose Node.js Core from the Libraries drop-down list.
Configuring a library added via a CDN link
When a library
.js file is referenced through a CDN link, it is available for the runtime but is invisible for PyCharm. To add the objects from such library
.js file to completion lists, download the file and configure it as an external library.
To download a library
Optionally By default, PyCharm marks the downloaded library as Global, which means that you can enable and re-use it in any other PyCharm project. To change this default setting, select the downloaded library in the list, click Edit, and choose Project in the Edit Library dialog that opens.
- Download the required framework file.
- By default, the library is Global, which means that you can attach it to any other project. To suppress re-using a library, choose Project in the New Library dialog.
- By default, the library is enabled in the scope of the whole current project. You can change this default setting as described in Configuring the scope of a library.
- In the Documentation URLs area, specify the path to the official documentation of the library or framework. PyCharm will open this URL when you press Shift+F1 on a symbol from this library.
Viewing the libraries associated with a file
- Open the file in the editor or select it in the Project view and click on the Status bar. PyCharm opens a pop-up window that lists the libraries associated with the current file.
- To change the list, click the Libraries in scope links and edit the scope settings in the Manage Scope dialog that opens.
- To remove the current file from a library's scope, clear the tick next to this library.
- To associate a library with the current file, set a tick next to this library.
Deleting a library
- Select the required library and click Remove.