libspec not being created for python files when path relative to pythonpath is ussed
Describe the bug
I am seeing robotframework-lsp unable to generate the libspec for a python file when using paths relative to the VSCode ${workspaceFolder} with the Library import line highlighted with red line and message:
Unresolved library: resources/os_utils.py.
Error generating libspec:
Importing library 'os_utils' failed: ModuleNotFoundError: No module named 'os_utils'
Consider adding the needed paths to the "robot.pythonpath" setting
and calling the "Robot Framework: Clear caches and restart" action.
robot.pythonpath is set correctly in the VSCode settings. It can be seen being passed correctly when executing the test with play button --pythonpath /home/callum/work/robot-test/lib is included in the command line
In the logs I observe:
Generating libspec for: os_utils.
Cwd:None
Command line:
/home/callum/work/robot-test/.venv/bin/python -m robot.libdoc --format XML --specdocformat RAW os_utils /home/callum/.robotframework-ls/specs/v2/5582c7a4_7.2.2/user/os_utils.libspec
server-api: 2025-05-16 09:53:21 UTC pid: 661920 - ThreadPoolExecutor-0_0 - EXCEPTION - robotframework_ls.impl.libspec_manager
Error creating libspec: os_utils.
Return code: 252
Output:
Importing library 'os_utils' failed: ModuleNotFoundError: No module named 'os_utils'
Traceback (most recent call last):
None
PYTHONPATH:
/home/callum/work/robot-test
/usr/lib/python313.zip
/usr/lib/python3.13
/usr/lib/python3.13/lib-dynload
/home/callum/work/robot-test/.venv/lib/python3.13/site-packages
Note that Cwd is not set so the module can not be found.
If the Library resources/os_utils.py is changed to Library ../resources/os_utils.py then the libspec is correctly generated.
To Reproduce
Project uploaded to: https://github.com/cloudchaserX/robot-test/
With the following files:
resources/os_utils.py:
import os
from robot.api.deco import library, keyword
@library(scope='GLOBAL')
class OSUtils:
@keyword("Check OS")
def check_os(self):
return os.name
tests/sample_test.robot:
*** Settings ***
Library resources/os_utils.py
*** Test Cases ***
Sample Test Case
${response}= Check OS
Log To Console ${response}
.vscode/settings.json:
{
"robot.pythonpath": ["${workspaceFolder}"],
"robot.language-server.args": ["-vv", "--log-file=/home/callum/work/robot-test/logs/robot.log"],
}
Expected behavior
Expected that libspect is generated. Cwd should be passed to the libspec generation command.
Screenshots
Versions:
- OS: Ubuntu 22.04
- Robot Framework Version: 7.2.2
- Robot Framework Language Server Version: 1.13.0
- Client Version: VSCode 1.99.3
Logs Obtained from clearing caches and restarting: robot_logs.tar.gz
I've also been struggling with the same issue for days. Could you help fix this problem?
- OS: Windows 10 22H2
- Robot Framework Version: 6.1.1
- Robot Framework Language Server Version: 1.13 .0
- Client Version: VSCode 1.99.0
I also did most testing such as downgrading the lsp from 1.13.0 to 1.9.0, even 1.5.0. there are also have the same issue. I'm not sure may be this issue related to the VSCode release. I'm very sure the lsp works fine in the year before last.