El Marce
El Marce

Reputation: 3344

PyCharm. Getting the Project Dir in the "Run/Debug Configuration" Window

I want to share PyCharm run/debug configurations with my team. I need a way of configure run/debug configurations so they can work also in other computers.

Is there a dynamic way of getting the project's dir? Any ideas?

Perhaps a way to change say "C:\PythonPlatform\Test\" to something like "${PROJECT_DIR}\Test" in the "Folders" and "Working directory" fields? See the image:

enter image description here

Upvotes: 13

Views: 7131

Answers (2)

As a silly workaround for the very specific but common case of running a main.py script in the project root, you can select to run by "Mondule name" instead of the default "Script path":

enter image description here

This works because the "Add source roots to PYTHONPATH" is ticked (default).

Tested in Pycharm CE 2019.2.3, Ubuntu 19.04.

Upvotes: 2

Piotr Dobrogost
Piotr Dobrogost

Reputation: 42425

There are so called Macros in PyCharm which include $ProjectFileDir$ described as The directory of the project file. However it seems they can only be used in External Tools section and not in Run/Debug Configurations. However, there's very relevant issue titled Add support for macros in Run/Debug Configurations screen raised in another JetBrains' product — WebStorm. There, we find information that the path to any file underneath project's directory is stored relatively to the project's directory meaning that if the project is placed somewhere else in the filesystem the file would still be found. In other words paths you see are presented as absolute paths but they are in fact relative to the project's directory. I must admit it's confusing to say the least.

I created issue Add support for macros in run/debug configurations — feel free to vote on it.

Upvotes: 10

Related Questions