robocorp / robotframework-lsp

Robocorp extensions for VS Code: Robocorp Code and RFW LSP
https://robocorp.com/docs/developer-tools/visual-studio-code
Apache License 2.0
202 stars 91 forks source link

Pycharm Language server plugin is not using the venv python executable. It seems that Robot Framework is not installed. #1011

Open bayank opened 9 months ago

bayank commented 9 months ago

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:

  1. Robot Framework Language Server plugin installed

  2. 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

  3. In the pycharm integrated terminal (venv is activated): a. 'which python' returns '/Users/bayank/PycharmProjects/robot_demo/venv/bin/python '

  4. 'pip install robotframework' a: 'which robot' returns '/Users/bayank/PycharmProjects/robot_demo/venv/bin/robot'

  5. 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

image
  1. 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_robotmain.py", line 673, in main() File "/Users/bayank/Library/Application Support/JetBrains/PyCharm2023.2/plugins/robotframework-intellij/lib/robotframework_debug_adapter/run_robotmain.py", line 650, in main import robot ModuleNotFoundError: No module named 'robot'

Robot Run Terminated (code: 0)



<img width="1391" alt="image" src="https://github.com/robocorp/robotframework-lsp/assets/30418939/f2d4a937-9063-474f-bedc-81ede9706563">

**Expected behavior**
The plugin should be aware of the venv im using and have activated and point to the venv python executable.

**Recovery**
1. 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**
<img width="1108" alt="image" src="https://github.com/robocorp/robotframework-lsp/assets/30418939/93a9e03e-0f41-4e5e-bd27-dadcae2c8233">

**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:

<img width="1116" alt="image" src="https://github.com/robocorp/robotframework-lsp/assets/30418939/5ddb7ba4-174d-4b0a-a168-1d38211b7756">
trongthanh commented 3 weeks ago

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.