Reputation: 484
When I use vim
to update my environmental variables (in ~/.bashrc
), PyCharm does not get the updates right away. I have to shut down the program, source ~/.bashrc
again, and re-open PyCharm.
Is there any way to have PyCharm source the changes automatically (or without shutting down)?
Upvotes: 49
Views: 48961
Reputation: 2843
Just click the EnvFile tab in the run configuration, click Enable EnvFile and click the + icon to add an env file
Upvotes: 1
Reputation: 1
from dotenv import load_dotenv
load_dotenv(override=True)
Python-dotenv can interpolate variables using POSIX variable expansion.
With load_dotenv(override=True) or dotenv_values(), the value of a variable is the first of the values defined in the following list:
With load_dotenv(override=False), the value of a variable is the first of the values defined in the following list:
Upvotes: 0
Reputation: 71
I know this is very late, but I encountered this issue as well and found the accepted answer tedious as I had a lot of saved configurations already.
The solution that a co-worker told me is to add the environment variables to ~/.profile instead. I then had to restart my linux machine and pycharm picked up the new values. (for OSX, I only needed to source ~/.profile and restart pycharm completely)
One thing to be aware is that another coworker said that pycharm would look at ~/.bash_profile so if you have that file, then you need the environment variables added there
Upvotes: 7
Reputation: 965
In my case pycharm does not take env variables from bashrc even after restarting
Upvotes: 18
Reputation: 91
I recently discovered a workaround in windows. Close Pycharm, copy the command to run Pycharm directly from the shortcut, and rerun it in a new terminal window: cmd, cmder, etc.
C:\
λ "C:\Program Files\JetBrains\PyCharm 2017.2.1\bin\pycharm64.exe"
Upvotes: 7
Reputation: 9692
In case you are using the "sudo python" technique, be aware that it does not by default convey the environment variables.
To correctly pass on the environment variables defined in the PyCharm launch configuration, use the -E
switch:
sudo -E /path/to/python/executable "$@"
Upvotes: 1
Reputation: 7737
When any process get created it inherit the environment variables from it's parent process (the O.S. itself in your case). if you change the environment variables at the parent level, the child process is not aware of it.
PyCharm allows you to change the environment variables from the Run\Debug Configuration window. Run > Edit Configurations > Environment Variables ->
Upvotes: 28
Reputation: 179
Pycharm maintains it's own version of environment variables and those aren't sourced from the shell.
It seems that if pycharm is executed from a virtualenv or the shell containing said variables, it will load with them, however it is not dynamic.
the answer below has a settings.py script for the virtualenv to update and maintain settings. Whether this completely solves your question or not i'm not sure.
Pycharm: set environment variable for run manage.py Task
Upvotes: 8
Reputation: 1654
This is simply how environment variables work. If you change them you have to re-source your .bashrc (or whatever file the environment variables are located in).
Upvotes: 0