Installing fortls without root and using modulefiles

I hope that this could be the right place to ask help, not strictly on Fortran syntax but on fortls.
I would like to install fortls so I can use VS code to edit Fortran files on a remote machine.

But, I don’t have root access to it, moreover if I need to run python I need to load a modulefile (with a specific Python version). And perhaps install fortls inside a virtual environment.

I can connect to this remote machine with VScode by ssh, and I can load files. As expected, it tells me Error spawning fortls, and no way to automatically install it.


Hi @egio so there are a couple of ways one can go when it comes to running Python on remote machines.

For Linux I think the easiest way to do this is call Python (which ships with pip) and do something like

/usr/bin/python -m pip install --user --upgrade fortls

This will install fortls in your home directory, I think by default that is ~/.local/bin/fortls. You can then point in your remote settings to that path via the option

"fortran.fortls.path": "/your/abs/path/to/fortls",

Alternatively, you can download miniconda and install fortls through the anaconda pip or conda-forge channel. I recommend pip since it will autoupdate. Again, all of this is done on a User level so no root access is needed.

Is not working yet.
I’ll tell you what I have done:
fist loaded the module where python is available something like:
module load python3.10
The I created a virtual environment in a subdirectory:

cd prova/python
python -m venv venv

then I activated it and installed fortls following your instructions (without --user as I am in a virtual environment).
Just as a test, outside the virtual environment I had the following error:

<g2egiova@s54 ~>/afs/
program pluto
Content-Length: 125
Content-Type: application/vscode-jsonrpc; charset=utf8

{"jsonrpc":"2.0","method":"window/showMessage","params":{"type":1,"message":"Unexpected error: Line endings must be \\r\\n"}}Unexpected error: Line endings must be \r\n
Traceback (most recent call last):
  File "/afs/", line 114, in run
    request = self.conn.read_message()
  File "/afs/", line 102, in read_message
    return self._receive()
  File "/afs/", line 87, in _receive
    length = self._read_header_content_length(line)
  File "/afs/", line 74, in _read_header_content_length
    raise JSONRPC2ProtocolError("Line endings must be \\r\\n")
fortls.jsonrpc.JSONRPC2ProtocolError: Line endings must be \r\n

Well I’m in linux so the termination is not \r\n but just \n

In VScode I had the same message of Error spawning, etc.
even though the remote setting is :

    "fortran.fortls.path": "/afs/"

Is there somewhere some logging file so I can try to understand the problem?

there may have been a conflict with Fortran intellisence of Chris Hansen.
But now I have another strange message:
“Failed to update fortls”
But it looks like is working

As you pointed out, the FORTRAN Intellisense is not compatible with Modern Fortran or fortls. The failed to install I suspect has to do with fortls not being able to go online and look at and then update. You will have to post the relevant bits of the log from the Modern Fortran Output channel.

Alternatively, you can pass the option --disable_autoupdate which will skip the PyPi check completely, however you then run the risk of using an outdated version of fortls and we only support the latest version.

Slightly off-topic but I guess it is not worth starting a new thread.

AFAIU fortls requires Python 3.7+. Many recent Linux distros install Python 3.x as python3, pip3 etc. In some older ones there are both 2.x and 3.x branches with python typically linked to python2. Now in the fortls docs there are instructions to use python/pip to install. So my question is whether the server will work properly if it is installed using python3/pip3?

Pip3 is just an alias to pip. As long as it’s python 3.7 it will work. There are full unit tests and integration tests for all python distros from 3.7 to 3.11 on Linux and windows