Best way to update scripted environment variables for a PyCharm controlled operation?


I use PyCharm for Django development, with my database host being driven by an environment variable. When working on the command line outside of PyCharm, I have a script that determines the available database hosts and gives me a list to select from. Typically I keep a PyCharm-managed Debug runserver operation running for my local testing and development.

As of now, whenever I want to change the targeted database, I update my fish configuration file with the relevant environment variable value, and restart PyCharm. I was wondering what better options there might be, such as a way to apply my command-line selection script from inside PyCharm to the whole PyCharm environment.


Hi Andrew,

I do not know your configuration, but maybe you could achieve that with Startup Tasks or Before Launch? There is no separate feature in PyCharm for such task at the moment.
Please also vote for if you find it useful.


I'm running local development on a Mac. I don't think either of those are workable solutions on their own--I don't want to have to exit the project in order to apply my environment variable change, and I don't want my selection prompt to occur on every time that the runserver runs or reloads. I can map the selection script to an external tool entry, or run it in the IDE's console, but the environment variable set inside each of those does not propagate to the rest of the IDE.

Is there a way to get a handle on either the IDE's environment variables from any of those environments, or possibly some sort of IDE session variable that I can use to pass settings around in?


Sorry, this isn't possible to do. Environment variable is loaded on the application startup and there is no out of the box way to update it when PyCharm is already running. 

Please feel free to submit a feature request about it to our issue tracker using the link and let us know if you need any help.


Please sign in to leave a comment.