I'm not native english speaker. I try to explain with my best. But if it's not clear, forgive me.
If you want your conda env vars available to your GUI app like Spyder, launch your GUI app from terminal after activating the conda env.
GUI apps launched by desktop don't know them (even if you installed the GUI app in your conda environment).
It's better to think about login, interactive and non-interactive shells and about .bashrc
and .bash_profile
files. Please read the following text for more details.
Normally, in Unix systems, we have login shells and interactive shells (see this):
A login shell, like the one you get when you first log in, reads specific startup files that configure your environment variables and personalize your experience. Interactive shells launched afterwards, say by opening a new terminal window, don't automatically read those same startup files. So, a login shell sets up your environment, while interactive shells you launch yourself inherit that environment.
You can define your permanent environment variables in .bashrc
and .bash_profile
. These methods have some differences. Spyder and programs launched by desktop will see the environment variables defined for login shells (defined in .bash_profile
). If you launch Spyder from terminal, you will see variables for both login and interative shells (defined in .bashrc
or .bash_profile
, and variables defined by conda env config vars set
).
From RedSwitches:
The main difference lies in when each file is executed. The .bashrc
file is executed for non-interactive, command-line shell sessions, while the .bash_profile
file is executed for login shell sessions, such as when you log into your system or remotely via SSH.
To see differences, you can define two variables, BASHRC_VAR
in your .bashrc
and BASHPROFILE_VAR
in .bash_profile
:
echo "export BASHRC_VAR=\"I'm Defined\"" >> ~/.bashrc
echo "export BASHPROFILE_VAR=\"I'm Defined\"" >> ~/.bash_profile
To apply environment variables to login shells, logout from your desktop and login again. Then run the following program in normal terminal and in the Spyder:
import os
for v in ['BASHRC_VAR', 'BASHPROFILE_VAR']:
print(v, end=': ')
try:
print(os.environ[v])
except:
print('Undefined!')
Result from normal terminal:
BASHRC_VAR: I'm Defined
BASHPROFILE_VAR: I'm Defined
Result from Spyder:
BASHRC_VAR: Undefined!
BASHPROFILE_VAR: I'm Defined
If you launch Spyder from terminal, the result will be:
BASHRC_VAR: I'm Defined
BASHPROFILE_VAR: I'm Defined
So, environment variables defined in .bashrc
and also variables defined by conda env config vars set
are not visible in Spyder. You must define your variables in .bash_profile
or you must launch Spyder from the terminal.
Solutions to your problem:
- Define your environment variables in
.bash_profile
, and login again.
- Launch Spyder from terminal (not by clicking on dekstop icons)
- Use config files (
.ini
, .config
, .yaml
, .json
) and use configparser or similar solutions.
- Use environment variables and config files together with some defined priorities