Path variables
Use path variables to define absolute paths to resources that are not part of a specific project. These external resources may be located in different places on the computers of your teammates. This is why user-defined custom path variables are not stored as project settings, but as global IDE settings. Once configured, such path variables will have the same value for any project that you open with your instance of PyCharm.
Create a new path variable
Press Control+Alt+S to open the IDE settings and then select
.Click , enter the name and value of the variable, and click OK to apply the changes.
You can use path variables to specify paths and command-line arguments for external tools and in some run configurations.
For example, you can define a path variable that points to the location of some data source (like a CSV file) or a third-party library that is not stored in your project. If you use this path variable in a run configuration that you share with your project, others can define the correct value for this path variable in their environment and be sure that the run configuration will work for them.
Refer to the variable as $var_name$
in fields and configuration files that accept path variables.
PyCharm also has the following built-in path variables:
- $USER_HOME$
The current user's home directory.
- $PROJECT_DIR$
The current project's root directory.
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.
Press Control+Alt+S to open the IDE settings and then select
.Click and 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.Share the run/debug configuration through your version control system.
Inspect the <project directory>.idea/runConfiguration/<configuration name>.xml file:
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.
Ignore path variables
Whenever you open or update a project, PyCharm checks for unresolved path variables. If the IDE detects any, it will ask you to define values for them. 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 when a program argument passed to the run/debug configuration has the same format as a path variable (for example, an environment variable).
Press Control+Alt+S to open the IDE settings and then select
.Add the names that PyCharm shouldn't consider to be path variables to the Ignored Variables field.
Click OK to apply the changes.