PyCharm 2019.3 Help

Command-line interface

Use PyCharm features from the command line: open files and projects, view diffs, merge files, apply code style formatting, and inspect the source code.

Launcher for a standalone instance

The installation directory contains batch scripts and executables for launching PyCharm, formatting the source code, and running inspections. To use them from the Command Prompt cmd.exe, add the location of the PyCharm bin folder to the PATH environment variable. For example, if you installed PyCharm to C:\Program Files\JetBrains\PyCharm, you can use the following command:

set PATH=%\PATH%;C:\Program Files\JetBrains\PyCharm\bin

This command changes the PATH environment variable for the current shell only (the current instance of cmd.exe). If you want to update it permanently for the current user, run setx. To update it system-wide for all users, run setx /M.

After you configure the PATH variable, you can run pycharm.bat from any working directory in the Command Prompt. Depending on the arguments that you pass to the script, it can do the following:

Argument

Description

No argument

Launch PyCharm.

Path to file or directory

Open the file or directory specified as the argument.
For more information, see Open files from the command line.

diff

Open the diff viewer to see differences between two files specified as arguments.
For more information, see Compare files from the command line.

merge

Open the Merge dialog to merge files specified as arguments.
For more information, see Merge files from the command line.

format

Apply code style formatting to the specified files.
For more information, see Format files from the command line.

inspect

Perform code inspection on the specified project.
For more information, see Run code inspections from the command line.

To run PyCharm from the shell, use the open command with the following options:

  • -a: Specifies the application

  • --args: Specifies additional arguments when passing more than just the file or directory to open

  • -n: Open a new instance of the application even if one is already running

For example, if the application is named PyCharm.app, you can run it using the following command:

open -na "PyCharm.app"

You can create a shell script with this command in a directory from your PATH environment variable. For example, create the file /usr/local/bin/idea with the following contents:

#!/bin/sh open -na "PyCharm.app" --args "$@"

Make sure you have permissions to execute the script and since /usr/local/bin should be in the PATH environment variable by default, you should be able to run pycharm from anywhere in the shell. Depending on the arguments that you pass to the launcher, it can do the following:

Argument

Description

No argument

Launch PyCharm.

Path to file or directory

Open the file or directory specified as the argument.
For more information, see Open files from the command line.

diff

Open the diff viewer to see differences between two files specified as arguments.
For more information, see Compare files from the command line.

merge

Open the Merge dialog to merge files specified as arguments.
For more information, see Merge files from the command line.

format

Apply code style formatting to the specified files.
For more information, see Format files from the command line.

inspect

Perform code inspection on the specified project.
For more information, see Run code inspections from the command line.

On Linux, the installation directory contains the launcher shell script pycharm.sh under bin. For example, if you installed PyCharm to /opt/pycharm, you can run the script using the following command:

/opt/pycharm/bin/pycharm.sh

You can create a symbolic link to the launcher script in a directory from the PATH environment variable. For example, if you installed PyCharm to /opt/pycharm and want to create a link named idea in /usr/local/bin, run the following command:

ln -s /opt/pycharm/bin/pycharm.sh /usr/local/bin/pycharm

Since /usr/local/bin should be in the PATH environment variable by default, you should be able to run the pycharm command from anywhere in the shell. Depending on the arguments that you pass to the script, it can do the following:

Argument

Description

No argument

Launch PyCharm.

Path to file or directory

Open the file or directory specified as the argument.
For more information, see Open files from the command line.

diff

Open the diff viewer to see differences between two files specified as arguments.
For more information, see Compare files from the command line.

merge

Open the Merge dialog to merge files specified as arguments.
For more information, see Merge files from the command line.

format

Apply code style formatting to the specified files.
For more information, see Format files from the command line.

inspect

Perform code inspection on the specified project.
For more information, see Run code inspections from the command line.

Shell scripts generated by the Toolbox App

If you are using the Toolbox App to install and manage JetBrains products, it can create shell scripts for launching your IDEs from the command line.

Generate shell scripts

  1. Open the Toolbox App and click the screw nut icon in the top right corner.

  2. In the Toolbox App Settings, enable Generate shell scripts.

  3. If necessary, change the shell scripts location.

Set scripts path in Toolbox

If you have several versions of the same IDE, the Toolbox App generates a shell script for each version with a unique name. You can change the name of the shell script for an IDE instance in the settings for this specific instance:

  1. Open the Toolbox App.

  2. Click the screw nut icon next to the relevant IDE instance and select Settings.

  3. At the bottom, change the Shell script name field.

Generation in Toolbox

By default, the Toolbox App puts shell scripts in a directory from the system PATH environment variable, so you can run the name of the script as a command to launch PyCharm from any working directory.

Last modified: 2 April 2020