Install Pyright on Ubuntu and Linux

Installing Pyright On Linux

Pyright finds mismatched types before Python reaches the affected line. Install it in your project, run it through npx, and keep its configuration beside the code it checks.

Install Pyright in your project

The npm package requires Node.js 14 or later, and a project-local install keeps the checker version in the project’s package manifest so a collaborator or continuous integration job can run the same command without a machine-wide npm install.

npm install --save-dev pyright

Run the local executable with npx to confirm that npm installed the command-line package and that your shell can invoke it.

npx pyright --version

If you prefer one command available outside a project, Microsoft also documents npm install -g pyright. Use the project-local route when the checker belongs to a repository, because the dependency is visible in package.json instead of depending on an administrator-installed copy.

Check a Python file

Type annotations describe the values a function accepts and returns, and Pyright compares a call against those annotations without running the program.

def add(left: int, right: int) -> int:
    return left + right

print(add(10, "20"))

Save the example as sample.py, then run Pyright from the project root.

npx pyright sample.py
Pyright reports a string passed to an integer parameter
Pyright identifies the incompatible argument before the script runs.

The diagnostic identifies the second argument as a string where add expects an integer. Change the value to 20, then run the same command again until Pyright reports no errors.

Add a focused Pyright configuration

Pyright reads pyrightconfig.json from the project root and also supports a tool.pyright section in pyproject.toml, although pyrightconfig.json takes precedence when both files exist.

{
  "include": ["src"],
  "exclude": ["**/__pycache__"],
  "pythonVersion": "3.13",
  "pythonPlatform": "Linux",
  "typeCheckingMode": "standard"
}

Set include to the source directories that belong to your application, and exclude generated directories only when they are outside the code you need to check because an excluded module can still be analyzed when an included file imports it.

Use pythonVersion when your deployment target differs from the Python interpreter on your workstation so Pyright applies language support and type stubs for that target version.

Choose a type-checking mode deliberately

Pyright supports off, basic, standard, and strict modes, with standard as the documented default for a typed application that is not ready for strict rules everywhere.

Strict mode can expose missing annotations and weaker assumptions in an established codebase, so apply it to a directory or package after standard mode is useful there and fix the reported diagnostics rather than suppressing them wholesale.

What Pyright does not check

Pyright checks the consistency of your annotated and inferred types but does not execute the program, validate database contents, prove business rules, or replace unit and integration tests.

Dynamic Python can reduce what a static checker can infer, so keep type annotations at interfaces such as function parameters, return values, data models, and library boundaries, then use tests for behavior that depends on runtime data.

Run Pyright before you commit

Add the npx pyright command to your local check or continuous integration workflow after the first clean run, then use the official Pyright configuration reference when your project needs import paths, execution environments, or stricter diagnostics.