Well I thought I had set up my conda environment in Pycharm just like their docs require:
- Settings > Project Interpreter > Add
- Select Conda Environment
- Check existing environment
- Browse for interpreter path (in this case
C:\ProgramData\Anaconda2\envs\wps_env36\python.exe
) - Click OK
I did notice, however that the environment was not automatically called in the 'Terminal' tab in PyCharm. So I followed this post which seems to adequately set it up for the terminal (although in my opinion that should automatically be taken care of when I select the environment above).
Now the confusing part: I tried to run the following in 3 different places in pycharm. These are 1) regular script, 2) Python Console, and 3) Terminal (by doing python
and forcing it into python interpreter mode`:
import os
print(os.environ['CONDA_PREFIX'])
For cases 1) and 2) I get the following error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\ProgramData\Anaconda2\envs\wps_env36\lib\os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'CONDA_PREFIX'
For case 3) it runs fine and outputs the path for the conda environment:
C:\ProgramData\Anaconda2\envs\wps_env36
This indicates to me that although the right python.exe
is used to run the interpreter, the necessary environment variables are not transferred automatically. I need these variables to do additional things, and I think the above explains why I have to add the following environment variables to my build configurations:
GDAL_DATA
PROJ_LIB
In the regular anaconda prompt/pycharm terminal these are already defined (as they originate from the batch scripts in C:\ProgramData\Anaconda2\etc\conda\activate.d
, but they are not defined in my main anaconda python interpreter.
How do I make sure the entire conda environment is defined in Pycharm as my main interpreter. I am talking complete with environment variables and any other shenanigans I am not aware of? The docs only indicate how you can set conda as your interpreter, and this is not enough in my case.