robotcode icon indicating copy to clipboard operation
robotcode copied to clipboard

[BUG] Invalid python version

Open maxgerhardt opened this issue 2 years ago • 4 comments

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

  • VS Code Version: 1.83.0
  • RobotCode Version: 0.60.0
  • OS: Linux (Ubuntu 22.04)
  • Python Version: 3.9.7
  • RobotFramework Version: 6.0.2

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 avatar Oct 05 '23 16:10 maxgerhardt

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

maxgerhardt avatar Oct 05 '23 16:10 maxgerhardt

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.

d-biehl avatar Oct 05 '23 20:10 d-biehl

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.

maxgerhardt avatar Oct 05 '23 20:10 maxgerhardt

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.

Natombrio avatar Feb 23 '24 11:02 Natombrio