Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using system environment variables in spyder

I have a program coded in Python 2 that I need to run and I would like to run it in spyder via anaconda software. The issue is that to run the program via the terminal I had to previously add in my system environment variables two new variables: 1) one folder in the computer where some required packages are 2) a variable with the ip address for the required license.

Although I have these variables define and the program runs without issues in the terminal. When I run it in spyder there is an error because it is not using those variables.

How can I fix this? I head something about anaconda creates virtual environments that is not loading those variables but I could not understand anything else. For example if I use pycharm, outside anaconda, it also works flawlessly

Thank you! Emanuel

like image 882
ECrespo Avatar asked Feb 13 '20 14:02

ECrespo


2 Answers

I believe Anaconda offers instructions on setting environment variables but that approach seemed complicated.

Setting an environment variable no longer seems to be an option in Spyder.

As a workaround Spyder does allow you to specify a startup file: Preferences -> IPython Console -> Startup

In the startup file you just run something like:

import os
os.environ['my_var'] = 'my_value'
os.environ['test'] = 'test_value'

Every time you start a new ipython console this code will run.

like image 188
Jimbo Avatar answered Oct 16 '22 04:10

Jimbo


There's an option in the Tools menu that let's you check/insert/update/remove the currently active environment variables in Spyder (pic for reference).

Spyder Environment Variables Feature

Edit: Regarding your PS question, when you install packages (through pip?) you are doing so through the currently active Python installation, which you can check by running

python -V

Therefore, if you intend to install a package in multiple installations, you need to use the corresponding package manager executable.

like image 27
João Amaro Avatar answered Oct 16 '22 05:10

João Amaro