How to specify a virtual Python environment in the RF-LS extension for VSC?

Hi,

There is a setting for the Robot Framework language server extension for Visual Studio Code: robot.python.env.

The documentation says about that setting:

“Can be used to set the environment used by robot.python.executable. Specifies the environment to be used when loading robotframework code and dependent libraries. I.e.: {“MY_ENV_VAR”: “some_value”}.”

Now, I have successfully set the robot.python.executable setting (as well as other settings).

But no matter what I try, I can’t force the usage of a particular virtual environment through the robot.python.env setting.

I can only force the usage of an env, by directly setting the robot.python.executable to such an env.

It comes down to that I don’t know what ‘some_value’ could be. I tried all kinds of stuff. :frowning:

Set-up:

VSC: 1.54.3
RF Language Server extension: 0.10.0
Python global installation: 3.9.
Python virtual env: based off 3.7
RF: 3.2.2

Thanks in advance for any suggestions!

Michael

1 Like

I had the same problem with robot.python.env in settings.json not working. I also tried setting the env value in the launch.json configuration for robotframework-lsp. It also didn’t work.

So had to add to my .bashrc file as a workaround. Would be nicer to have in one of those .json files.

Hi, you can add to the settings.json file the following line
“robot.python.executable”: “${workspaceFolder}\venv\scripts\python.exe”,

this will use the python defined in your virtual environment (assuming ‘venv’ is the virtual environment name).