Modern Fortran on vscode in WSL 2 Ubuntu - fortls problem

Hello, as the title suggests, I’m trying to use Modern Fortran (v3.2.0) in vscode (v1.84.2) in WSL 2 (Ubuntu 22.04.2 LTS) on Windows 10.

It’s the classic error that it doesn’t seem to be able to find fortls, even though I have tried to fix it!

fortls is installed (via pip), and opening a terminal in vscode, “fortls --version” gives 2.13.0

I can see fortls in the folder /usr/local/lib/python3.10/dist-packages, so I have set “fortran.fortls.path”: “/usr/local/lib/python3.10/dist-packages/fortls” in the Remote [WSL: Ubuntu] settings. This didn’t help so for good measure, I also tried setting this path in the User and Workspace settings in vscode too.

I then tried adding /usr/local/lib/python3.10/dist-packages to $PATH by modifying ~/.bashrc , and checked that this was successful using echo $PATH in a terminal in vscode (running in WSL: Ubuntu).

Sorry for a similar thread to previous ones, but I’m not sure what to do next, and perhaps vscode with WSL is a different case?

Best regards,

I would start by asking to install the pre-release of the modern fortran extension.
WSL should work automatically with fortls (at least that’s my experience and that’s what I’ve heard from others). That being said, if for whatever reason vscode can’t detect fortls then you need to specify the absolute path to the binary on Linux, Mac and WSL, from a terminal you can run

which fortls

And copy-paste that path into the vscode setting.

Here is where you went wrong

1 Like

FYI you can install the latest release candidate (rc1) of fortls by running

python3 -m pip install fortls --pre

Sorry, I realise I never said thank you!

Better late than never:

Thank you! This fixed it :slight_smile:

1 Like