default working directory

Answered
I'm running PyCharm 2.6.3

How do I set the default running directory for all Python run configurations?

I've tried going into Run/Debug Configuration->Defaults and setting the Working Directory field for the "Python" template.  However, whenever I right click on a script file and choose 'Run' the script is still run with the working directory set to where that script is located.  What am I missing?


Thanks
Dmitry
13 comments
At the moment there is no way to modify this behavior, other than creating the configurations manually. Configurations created by the "run script" action always have the working directory set to the directory of the script.
0
Thanks for a prompt reply.  This behavior is quite inconvenient with Django projects where a script file lives in an app directory, but still needs to be run relatively to the django project root.
0

Same issue here, I need to pass a `-c config-file` option to py.test, but I cannot create sane defaults:

- taking the working directory from defaults would solve my problem, but this is not the case as stated above

- I could not find a way to interpolate the "project root dir" variable in the "Additional arguments" field, otherwise I could have used something like `-c ${projectRoot}/config-file`. Also, I don't want to create a custom path variable as it won't work out of the box for my colleagues).

 

Until one of these two issues is fixed, for each new test that I want to run, I need to:

- run the test

- wait for it to fail because the configuration is wrong

- edit the configuration manually

- re-run the test

 

Not a great workflow, unfortunately...

0

Hi Romainchossart! I believe one can set default working directory for tests in default run configurations:

Make sure you are using the latest stable version. Has it helped in your case?

0

On my build (2017.1.2), setting this value has no effect when running a new test from the editor: the working directory is always set to the test file directory.

0

Yeap, this behaviour was recently fixed, would you mind trying 2017.1.4 or (2017.2 EAP)?

0

Ha, I confirm the behaviour is fixed on 2017.1.4, thanks! <3

0

I have this kind of structure for projects:

 

    project-name

         - src

         - tests

So root dir is project-name and all tests and source code should run with project-name as root directory. I change Templates setting, mark directory as source. But anyway, I still correct working directory manually every time when I run new test. 

 




 

PS after restart it began to work. Anyway. Is it marked in documentation how to setup run/tests config root directory? Firstly I looked at the dock, marking directory as source etc etc etc. And now figure it out. Looks like it is not very clear in documentation.

1

This works as a project-wide setting. How can this be set so that all default run configurations (across all projects) use the root path of the respective project?

0

Hi Fabio,

Thank you for contacting PyCharm support.

Maybe I have misunderstood, but have you tried https://www.jetbrains.com/help/pycharm/changing-default-run-debug-configurations.html?

Looking forward to your reply.

Kind regards,

Sergey

https://www.jetbrains.com

The Drive to Develop

0

Hi Sergey,

thanks for checking back.

As I said, this works fine on a per-project basis.

The issue is that I have to do this for every new project (and for run as well as test configurations) again every time.

I would like a default for all run configurations across all projects.

E.g. a global setting could have the value $PROJECT_ROOT so that all run configurations have the working directory default to their respective project root

Is it clearer now?

0

Thank you for the update.

Ah, I see.

No, unfortunately this isn't possible at the moment. See https://youtrack.jetbrains.com/issue/IDEA-65915 and https://youtrack.jetbrains.com/issue/IDEA-137080. Please vote for them and follow for future updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.

Kind regards,

Sergey

https://www.jetbrains.com

The Drive to Develop

0

Ok, thanks for the fast responses and the links. Will do.

0

Please sign in to leave a comment.