robotcodedev / robotcode

RobotFramework support for Visual Studio Code
https://robotcode.io
Apache License 2.0
168 stars 13 forks source link

[BUG] Invalid python version #165

Closed maxgerhardt closed 2 months ago

maxgerhardt commented 9 months ago

Describe the bug

In a project that has a virtual environment with Python 3.9.7, the Robot Framework extension complains that an invalid Python version was found and that only Python >= 3.8 is supported. However, Python 3.9.7 is equal or greater to 3.8. Especially comical is that the mouse-hover over "Robot Framework" also sees Python 3.9.7 as the version string. As a result, code completion and following custom-written keywords does not work at all.

To Reproduce Steps to reproduce the behavior:

  1. Prepare a project folder with a simple hello-world .robot file
  2. Create a virtual Python environment for 3.9.7 version (With miniconda 3.9 installation's python: python -m venv --symlinks env/py)
  3. Activate it (source env/py/bin/activate)
  4. pip3 install robotframework in it
  5. Start VSCode in that same shell
  6. See error

Expected behavior Robot extension recognizes the satisfied version constraint.

Screenshots/ Videos

image

image

image

Logs Copy the messages from VSCode "Output" view for RobotCode and RobotCode Language Server for the specific folder/workspace.

Activate RobotCode Extension.
Try to activate python extension
Python Extension is active
Invalid python version for workspace folder 'project'. Only python version >= 3.8 supported. Please update to a newer python version or select a valid python environment.
executeRobotCode: env/py/bin/python3 -u -X utf8 /home/max/.vscode/extensions/d-biehl.robotcode-0.60.0/bundled/tool/robotcode --format json --no-color --no-pager discover info
executeRobotCode: exit code 0

Desktop (please complete the following information):

Additional context

Python version in the activated PyEnv is miniconda3.

(py) max@XXXXXXX:~/project$ ls -la $(which python)
lrwxrwxrwx 1 max max 45 Feb 28  2023 /home/max/project/env/py/bin/python -> /opt/xxxxxx/miniconda3-py39_4.11.0/bin/python

Also, this is problem has occurred and disappeared recently at random times, mostly after some Robot Code extension updates or VSCode updates, it kind of alternative between working and nonworking. In it's most updated and most current state, it is not working.

maxgerhardt commented 9 months ago

..And of course, as soon as I post it, I find the error.

My .vscode/settings.json contained this option

{
    "robotcode.python": "env/py/bin/python3"
}

which worked with previous versions but not with the current one -- as soon as I comment it out and reload VSCode (and robot code caches), it starts working again. As soon as I activate it again and save the file, the error shows up again.

It seems there is a regression in how that option is handled?

d-biehl commented 9 months ago

I'll have to take a closer look later. Haven't actually changed any code that is responsible for the python selection....

But first a short answer:

The robotcode.python setting is actually not necessary, it should be enough to select the Python environment with VS Code, so via the "Python: Select Interpreter" command.

What I have noticed lately, Microsoft works heavily on the Python extension and builds new features and moves many tools (debugger, Mypy, Black) in their own extensions. And sometimes it forgets the Python interpreter for a project. This happened to me lately also in pure Python projects without having RobotCode installed. The solution for this is to simply select the correct Python interpreter again and then it should work again.

Nevertheless, and as mentioned above, I'll leave the issue open for now and take a closer look at it soon.

maxgerhardt commented 9 months ago

Just for completeness later: While robot code extension showed a "Select interpreter" panel, clicking on any of my Python 3.9.7 or Python 3.10 still showed the same "You must have Python >= 3.8" error message -- manual selection was thus also broken.

Natombrio commented 5 months ago

Some more info to hopefully help with debugging. I was running into the same issue with a basic venv setup on Windows. I was able to reproduce it reliably many times, but it seems that running vscode's >Python: Clear Workspace Interpreter Setting command fixed the issue for me and I couldn't repro the error state at all after this.