Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm not updating with environment variables

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)?

like image 579
RenaissanceProgrammer Avatar asked Nov 10 '15 20:11

RenaissanceProgrammer


People also ask

Do we need to update PATH variable for PyCharm?

It is not important to change the installation destination of the PyCharm application, but you could also change the destination to be directly on your C: similarly to the Python installation. However, we suggest simply going with the default path.

How do I reload environment variables in IntelliJ?

An IntelliJ IDEA plugin to automatically add environment variables to Path Variables. Environment variable are added to Path Variables with "env." prefix to avoid collisions. To reload the environment variables loaded: Tools -> Reload Environment Variables in Path Variables.

How do I set environment variables in PyCharm?

In addition, I have tried setting the environment variables in Preferences -> Build, Execution, Deployment -> Console -> Python Console / Django Console, but it sets the variables for the interpreter. You can set environmental variables in Pycharm’s run configurations menu.

Why does PyCharm say the environment is invalid?

If PyCharm warns you about an Invalid environment, the specified Python binary cannot be found in the file system, or the Python version is not supported. Check the Python path and install a new version, if needed. You can create as many virtual environments as required. To easily tell them from each other, use different names.

How to add environment variables to a Python project?

While your project is selected, click on Run -> Edit Configurations ... Give your run configuration a name and click on the folder icon in the Environment Variables text input: Click + to add a new environment variable. When you had create all the environment variables that you wish to supply to your Python application, click OK.

Does PyCharm pick the defined env var?

– alexey Sep 11 '17 at 18:17 6 I tried this method but PyCharm doesn't pick the defined env var (I specifically tried to set DATABASE_URL). Looks like a PyCharm bug. – LNI Nov 2 '17 at 1:14 2 @LNI in PyCharm there are two places where we can set env variables.


4 Answers

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 ->

Images

like image 117
omer727 Avatar answered Oct 02 '22 07:10

omer727


In my case pycharm does not take env variables from bashrc even after restarting

like image 39
Marat Zakirov Avatar answered Oct 02 '22 06:10

Marat Zakirov


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

like image 7
Ryan Cook Avatar answered Oct 02 '22 08:10

Ryan Cook


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

like image 7
Marc Avatar answered Oct 02 '22 08:10

Marc