Pycharm Language server plugin is not using the venv python executable. It seems that Robot Framework is not installed.
Describe the bug When I create a new project with the Robot Framework Language Server plugin in Pycharm, there is an error that It seems that Robot Framework is not installed.
To Reproduce Steps to reproduce the behavior:
-
Robot Framework Language Server plugin installed
-
Create a new empty pycharm project a. Select new environment using Virtualenv b. Location is project root directory: /Users/bayank/PycharmProjects/robot_demo/venv c. Base Interpreter: using Homebrew python installation: /opt/homebrew/bin/python3
-
In the pycharm integrated terminal (venv is activated): a. 'which python' returns '/Users/bayank/PycharmProjects/robot_demo/venv/bin/python '
-
'pip install robotframework' a: 'which robot' returns '/Users/bayank/PycharmProjects/robot_demo/venv/bin/robot'
-
Create a new .robot file and create the first line '*** Settings ***' and shortly after the ide error is visible saying Robot is not installed in some other directory that looks like its my system python that I never touch. I'm using venv for every python project.
Error in "import robot". It seems that Robot Framework is not installed in /Applications/Xcode.app/Contents/Developer/usr/bin/python3. Please install it in your environment and restart the Robot Framework Language Server or set: "robot.language-server.python" or "robot.python.executable" to point to a python installation that has Robot Framework installed. Hint: with pip it can be installed with: /Applications/Xcode.app/Contents/Developer/usr/bin/python3 -m pip install robotframework
- Also when I try to run the test I get this error
Error importing robot.
Python executable: /Applications/Xcode.app/Contents/Developer/usr/bin/python3.
Traceback (most recent call last):
File "/Users/bayank/Library/Application Support/JetBrains/PyCharm2023.2/plugins/robotframework-intellij/lib/robotframework_debug_adapter/run_robot__main__.py", line 673, in <module>
main()
File "/Users/bayank/Library/Application Support/JetBrains/PyCharm2023.2/plugins/robotframework-intellij/lib/robotframework_debug_adapter/run_robot__main__.py", line 650, in main
import robot
ModuleNotFoundError: No module named 'robot'
Robot Run Terminated (code: 0)
Expected behavior The plugin should be aware of the venv im using and have activated and point to the venv python executable.
Recovery
- Manually set the Language Server Python option in the plugin settings to the project venv python executable. In my case it's '/Users/bayank/PycharmProjects/robot_demo/venv/bin/python'
Screenshots
Versions:
- OS: MacOS Ventura 13.6.2
- Robot Framework Version: 7.0a2
- Robot Framework Language Server Version: 1.11.0
- Client Version: PyCharm 2023.2.5
Logs Add the logs obtained when reproducing the issue. See: https://github.com/robocorp/robotframework-lsp/blob/master/robotframework-ls/docs/reporting_issues.md for details on how to collect the logs.
I was unable to get logs because there is an error in the plugin settings when I attempt to set the environment variable while following the steps in the linked doc:
As this ticket is dated, but I think it's worth leaving our workaround in case anyone facing the same issue:
Somehow, the Robot Framework Language Server doesn't pick up the python executable for the project local Python interpreter. To work around, we have to explicitly set the Language Server Python config (as shown in the last screenshot above) with the absolute path to the local venv python executable. In the post author case, it is: /Users/bayank/PycharmProjects/robot_demo/venv/bin/python.