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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With