IDE: VSCode
Python 3.10 + RobotFramework 5.0.1
vscode extension: Robot Framework Language server 0.47.2
文件夹结构:
在libraries.resource 文件中,我将 dbutils 库称为:
Libraries ./libraries/Utilities/utils.py
在我的 utils.py 文件中,我将文件 dbutils.py 导入为:
from libraries.DBUtilities.dbutils import dbutils
class utils():
def __init__(self):
self.ut = dbutils()
通过此设置,robotframework 语言服务器会抛出如下错误:
Unresolved library: ../libraries/Utilities/utils.py
Error generating libspec:
Importing library 'utils' failed: ModuleNotFoundError: No module named 'utils'
Consider adding the needed paths to the "robot.pythonpath" setting
and calling the "Robot Framework: Clear caches and restart" action.robotframework
我已经尝试过了,
使用 Import 而不是 from
使用 try: 和 except:
将库添加到“robot.pythonpath”部分下的 vscode 工作区文件中
从 vscode 命令面板应用了“机器人框架:清除缓存并重新启动”
编辑1:
project workspace file has the following settings:
"robot.pythonpath": ["${workspaceFolder}/.venv/Scripts/python.exe", "${workspaceFolder}/libraries"],
"robot.language-server.python": "${workspaceFolder}/.venv/Scripts/python.exe",
"robot.python.executable": "${workspaceFolder}/.venv/Scripts/python.exe",
@Ruben 给出的答案是有效的,但在你的情况下,我想你必须在字段中设置环境路径,要获取该路径,只需使用以下命令:
echo $VIRTUAL_ENV