Working directory dependent on interpreter or executing machine


I have set up an ssh remote interpreter. Everything runs fine, except that the working directory on my local machine is different from that of the remote. Local is Windows and remote is Linux. Hence I have problems seeing how I could use a variable in the Working Directory input field in the Project Settings, since the reference would be $XYZ on Linux and %XYZ% on Windows. Is there some config file that I could put on each machine the could host the Working Directory path?

The reason is that the setup we’ve got depends os.getcwd() and that we several times we change between running on local and running on remote. Of course it is not difficult to change the Working Directory when you also change interpreter but the less moving parts the depend on manual human labor by me, the less error prone the workflow will be.

Any one with ideas on how to get around this?

Thanks a lot in advance!


Hi Peter,

>Hence I have problems seeing how I could use a variable in the Working Directory input field in the Project Settings, since the reference would be $XYZ on Linux and %XYZ% on Windows.

You could change working directory not in project settings, but for needed Run/Debug configuration (Run | Edit Configurations...). It also allows you to set environment variables when required.

Or do I miss something in your use-case?


Hi Sergey,

Thanks a lot for your prompt reply. Whether in the Project Settings or the Run/Debug Configuration I would still have to choose both interpreter as well as the Working Directory.

As I see it the Run/Debug Configuration is on a pr file basis (except from Templates). Sometimes I would like to run that file locally on my Windows laptop, sometimes I would like to run it on the remote (local could be for debugging on a subset of the problem I am working with, then remote on the entire problem still having the possibility to debug via Pycharm instead of pure command line "python".

This is super easy if not considering anything else the just shifting interpreter in the Run/Debug Configuration interpreter drop down, but becomes a little less easy if one also has to change Working Directory (or possibly other things like Environment Variables) that might look different between local and remote; in my case because local runs Windows and remote runs Linux.

So what I am after is some setup that sort of automates this. Could be (I think currently not possible) the option of defining several Configurations that could be chosen with a dropdown like having several Debug and several Run Configurations. It could also be done with a config file that I could place on local and remote that would have different values for this like Working Directory and the like. I looked through the .idea files, but saw nothing that looked like I could define that.

Does it make sense what I am after?

Thanks very much in advance for taking the time for helping me out!

Best, Peter


Ok. I guess what I could do it stop using the Run/Debug Configuration on a per file basis as is what default happens, but instead have a Debug Local and Debug Remote (and the same for Run) and then change the script that is run when I g from script to script. I have to say that I have really started to love the way Pycharm does this automatically... (Setting up new Config if the File has not been run yet, so on so forth)


Thank you for providing such a clear description. It totally makes sense.

I believe a better solution would be to have two Run/Debug configurations. One for remote run and debug, another for local run and debug. You can actually have as much as you need and have absolutely different configurations to run the same script. More than that, you can run them in parallel (just check corresponding option in the upper-right corner of your Run/Debug configuration).

You are right to say that PyCharm currently doesn't have a way to automatically define it and there are certain difficulties in implementing this. However, feel free to submit a feature request about it to our issue tracker using the link and let me know if you need any help.


Thanks a lot, Sergey. I have been off-line a couple of days so sorry for this late reply. However, I actually ended making my way according to the same track as you suggest above. It works actually super nice.

Best and thanks for your prompt replies



Please sign in to leave a comment.