PyCharm 2019.2 Help

Path Variables

Path variables are placeholders that stand for absolute paths to resources that are linked to your project but are stored outside it. If you are working in a team, these absolute paths on the computers of your teammates may differ. With path variables, you can flexibly share your code so all the references to the linked resources are resolved properly as the path variables accept the values according to the configuration on each specific computer.

In PyCharm, there are some pre-defined variables:

  • $USER_HOME$ — stands for your home directory.

  • $PROJECT_DIR$ — stands for the directory where your project is stored.

Create a new path variable

For example, you have a Python script that processes some data stored in your system in the reports.csv file. You create a run/debug configuration to run this script and want to share this configuration with your teammates through the VCS.

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Appearance & Behavior | Path Variables, and click the the Add button button.

  2. Enter the name of the new variable (for example, DATA_PATH) and its value that points to the target directory with the data file on your disk.

    Adding a new path variable

  3. Share the run/debug configuration through your version control system.

    Run/debug configuration

  4. Inspect the <project directory>.idea/runConfiguration/<configuration name>.xml file:

    Run/debug configuration file with the path variable added
    After your teammates update their projects from VCS, they will change the DATA_PATH variable value so that it points to the data directory on their computers.

Ignored path variables

When you open a project, PyCharm checks if there are any unresolved path variables. If the IDE detects any, it will ask you to define values for them. If for some reason you don’t want to do that (for example, if you are not going to use files or directories with the unresolved path variables), you can add them to the list of ignored variables.

You can also use the list of ignored variables if, for example, a program argument passed to the JVM in a run/debug configuration has the same format as an internal ($SOME_STRING$) path variable. In this case, you can add this parameter to the list of ignored variables in order to avoid confusion. Enter SOME_STRING to the Ignored Variables field in the Path Variables dialog.

Last modified: 20 August 2019