Thursday, October 6, 2022

[SOLVED] spyder set python interpreter at launch

Issue

I am trying to use Spyder with virtual environments. I have installed spyder-kernels and after launching Spyder, I can go into the gui and point to the correct python interpreter. Is there a way this can be done at launch so I don't have to go into the gui every time and update the interpreter when I change environment?


Solution

Not the answer you're looking for... but I was able to accomplish this by creating a script that modifies the following files before launching spyder. These two files are what get changed when you interactively change the interpreter in the preferences.

  • The main_interpreter section in ~/.config/spyder-py3/config/transient.ini. For example, if your venv path is PATH, then

    [main_interpreter]
    custom_interpreters_list = ['PATH/bin/python']
    custom_interpreter = PATH/bin/python
    executable = PATH/bin/python
    
  • Enable the custom interpreter in the main_interpreter section in ~/.config/spyder-py3/config/spyder.ini

    [main_interpreter]
    default = False
    custom = True
    

This is on linux - the .ini files may be on a different path in Windows.



Answered By - KCharlie
Answer Checked By - Senaida (WPSolving Volunteer)