python error in kconfig extension?

When loading the nRF Connect Plugin for VCS, I am receiving either a crash message or the message below. It looks like a Python syntax error in the kconfig extension. python should be pointing to python2 in the 1.7.0 SDK directory.

This is the output window

[Info - 3:08:26 PM] Connection to server got closed. Server will restart.
File "/Users/allencurtis/.vscode/extensions/nordic-semiconductor.nrf-kconfig-2021.11.7/srv/kconfiglsp.py", line 65
self.diags: Dict[str, List[Diagnostic]] = {}
^
SyntaxError: invalid syntax
File "/Users/allencurtis/.vscode/extensions/nordic-semiconductor.nrf-kconfig-2021.11.7/srv/kconfiglsp.py", line 65
self.diags: Dict[str, List[Diagnostic]] = {}
^
SyntaxError: invalid syntax
[Info - 3:08:26 PM] Connection to server got closed. Server will restart.
File "/Users/allencurtis/.vscode/extensions/nordic-semiconductor.nrf-kconfig-2021.11.7/srv/kconfiglsp.py", line 65
self.diags: Dict[str, List[Diagnostic]] = {}
^
SyntaxError: invalid syntax
[Info - 3:08:26 PM] Connection to server got closed. Server will restart.
File "/Users/allencurtis/.vscode/extensions/nordic-semiconductor.nrf-kconfig-2021.11.7/srv/kconfiglsp.py", line 65
self.diags: Dict[str, List[Diagnostic]] = {}
^
SyntaxError: invalid syntax
[Info - 3:08:26 PM] Connection to server got closed. Server will restart.
File "/Users/allencurtis/.vscode/extensions/nordic-semiconductor.nrf-kconfig-2021.11.7/srv/kconfiglsp.py", line 65
self.diags: Dict[str, List[Diagnostic]] = {}
^
SyntaxError: invalid syntax
[Error - 3:08:26 PM] Connection to server got closed. Server will not be restarted.
  • Hi Allen,

    I don't think /usr/local/bin/python is the v2.7 executable.  I base this upon the following result.

    % ls -la /usr/local/bin/python

    lrwxr-xr-x  1 root  wheel  16 Nov  9 09:30 /usr/local/bin/python -> /usr/bin/python3

    It seems the Mac OS is doing something unexpected with regard to the symbol links and python.

    I do see that within the /opt/nordic/ncs/v1.7.1/toolchain/bin/ directory there are a number of python3 related files.

    % ls -la /opt/nordic/ncs/v1.7.1/toolchain/bin/python*

    lrwxr-xr-x  1 petermurphy  staff  38 Nov  8 10:12 /opt/nordic/ncs/v1.7.1/toolchain/bin/python3 -> ../Cellar/[email protected]/3.9.6/bin/python3

    lrwxr-xr-x  1 petermurphy  staff  45 Nov  8 10:12 /opt/nordic/ncs/v1.7.1/toolchain/bin/python3-config -> ../Cellar/[email protected]/3.9.6/bin/python3-config

    lrwxr-xr-x  1 petermurphy  staff  40 Nov  8 10:12 /opt/nordic/ncs/v1.7.1/toolchain/bin/python3.9 -> ../Cellar/[email protected]/3.9.6/bin/python3.9

    lrwxr-xr-x  1 petermurphy  staff  47 Nov  8 10:12 /opt/nordic/ncs/v1.7.1/toolchain/bin/python3.9-config -> ../Cellar/[email protected]/3.9.6/bin/python3.9-config

    Based upon your suggestion here's what I've done.

    #1. Remove the earlier created symbolic link using 

    sudo rm /usr/local/bin/python

    #2. In my ~/.zprofile file add the following

    export PATH="/opt/nordic/ncs/v1.7.1/toolchain/bin:$PATH"

    #3. Now when I open a terminal window the PATH variable is as shown below.

    % echo $PATH

    /opt/nordic/ncs/v1.7.1/toolchain/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

    #4. Running which python3 we get the nordic version

    % which python3

    /opt/nordic/ncs/v1.7.1/toolchain/bin/python3

    #5. At this point which python still points to /usr/bin/python.

    % which python

    /usr/bin/python

    #6. And/usr/bin/python points to./../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7.

    % ls -la /usr/bin/python

    lrwxr-xr-x  1 root  wheel  75 Oct 17 20:30 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

    #7. I think what you're suggesting is that I overwrite the existing symbol link for /usr/bin/python to point to /opt/nordic/ncs/v1.7.1/toolchain/bin/python3.  As you can see below the Mac OS doesn't allow me to do that.

    petermurphy@Peters-MacBook-Pro ~ % sudo ln -s -f /opt/nordic/ncs/v1.7.1/toolchain/bin/python3 /usr/bin/python

    ln: /usr/bin/python: Operation not permitted

    Please let me know if I'm understanding you correctly.

    Since Nordic includes python3 in the /opt/nordic/ncs/v1.7.1/toolchain/bin/ isn't there a simpler way within some Nordic configuration file to tell the Nordic tools where to find the python executable?

    Regards,

    Peter

     

  • Hi Peter

    Peter Murphy said:
    Since Nordic includes python3 in the /opt/nordic/ncs/v1.7.1/toolchain/bin/ isn't there a simpler way within some Nordic configuration file to tell the Nordic tools where to find the python executable?

    Yes, nRF Connect for SDK should use its included toolchain. However, due to a current bug, it does not. Our developers are looking into this.

    The workaround is to set the default Python version to Python3.

    Your problem to do this at the moment is very MacOS related. To get better help with this, I advise you to seek help at other forums which are more focused at this area.

    Regards,
    Sigurd Hellesvik

  • Instead of mucking around with the system Python version, you can simply set the default interpreter in VS Code:

    1. Open VS Code settings
    2. Search for 'Python: Default Interpreter Path' 
    3. Change `python` to `python3` or your preferred path

    Edit: as Peter Murphy noted, the 'Default Interpreter Path' setting requires the 'Python' extension to be installed.

  • Hi peter_h,

    Thanks for your suggestion.  It sounds simple enough.  But I'm unable to find anything when I perform the "Python: Default Interpreter Path" search.  I've included a three screenshots showing you how I got to the window and performed the search. The first image shows where I found the Settings choice. The second shows the Settings window before I entered anything into the search bar.  The third shows that nothing is found when search for "Python: Default Interpreter Path". 

    The website https://code.visualstudio.com/docs/python/environments#_manually-specify-an-interpreter makes it sound like I need to install the "Python Extension Pack".  But as far as I know, installing the "Python Extension Pack" wasn't part of the Nordic VSC setup process.

    Regards,

    Peter

  • Hi Peter M,

    Right you are - the 'Default Interpreter Path' setting appears to be from the 'Python' extension (I don't have the 'Python Extension Pack' installed). It's a little confusing that the setting would be respected by KConfig, but it appears to work in my case.

    The Python extension is provided by Microsoft, presumably it's safe to install (while the extension pack is from a 3rd party, so who knows).

Related