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.
Parents
  • Hi Allen,

    The problem indeed seems to be that the nRF Connect Extension for VS code use "python", which for mac defaults to python 2.

    As a workaround, I was able to fix this by changing what python version "python" points to on the mac in general.
    Beware that this fix may change the behaviour of other applications using python on your computer.

    ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python

    Our developers know about this issue, and it might be fixed in our extension in the future. Thank you for the report!

    Regards,
    Sigurd Hellesvik

  • Hi Siguard,

    Today I ran into the same problem Allen did. I have a brand new MacBook Pro with OS Monterey v12.0.1. Python2 and Python3 were already installed on the machine when I purchased it.  Running the command which python within a terminal window results in the following:

    % which python

    /usr/bin/python

    Using the ls -la command we can see /usr/bin/python is a link to 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

    Using the which command and ls commands we can also see python3 is located in /usr/bin/python3 and that it’s not a link but the actual binary.

    % which python3

    /usr/bin/python3

    % ls -la /usr/bin/python3

    -rwxr-xr-x  1 root  wheel  137696 Oct 17 20:30 /usr/bin/python3

    Because my versions of python are not located in the /usr/local/bin directory the command you suggested (i.e., ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python) doesn’t work for me.  Instead I tried the command sudo ln -s -f /usr/bin/python3 /usr/bin/python. However, as you can see below I’m unable to successfully run this command.  

    % sudo ln -s -f /usr/bin/python3 /usr/bin/python

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

    I tried remove the link /usr/bin/python with the command sudo rm /usr/bin/python but that wasn't allowed (see below).

    % sudo rm /usr/bin/python

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

    Is there another workaround so that nRF Connect Extension for VS uses python3?

    Regards,

    Peter

Reply
  • Hi Siguard,

    Today I ran into the same problem Allen did. I have a brand new MacBook Pro with OS Monterey v12.0.1. Python2 and Python3 were already installed on the machine when I purchased it.  Running the command which python within a terminal window results in the following:

    % which python

    /usr/bin/python

    Using the ls -la command we can see /usr/bin/python is a link to 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

    Using the which command and ls commands we can also see python3 is located in /usr/bin/python3 and that it’s not a link but the actual binary.

    % which python3

    /usr/bin/python3

    % ls -la /usr/bin/python3

    -rwxr-xr-x  1 root  wheel  137696 Oct 17 20:30 /usr/bin/python3

    Because my versions of python are not located in the /usr/local/bin directory the command you suggested (i.e., ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python) doesn’t work for me.  Instead I tried the command sudo ln -s -f /usr/bin/python3 /usr/bin/python. However, as you can see below I’m unable to successfully run this command.  

    % sudo ln -s -f /usr/bin/python3 /usr/bin/python

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

    I tried remove the link /usr/bin/python with the command sudo rm /usr/bin/python but that wasn't allowed (see below).

    % sudo rm /usr/bin/python

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

    Is there another workaround so that nRF Connect Extension for VS uses python3?

    Regards,

    Peter

Children
  • Hi Peter,

    Looks like you covered all the possibilities except for one. I might be that the extension is looking for python in /usr/local/bin/python. So if you do this: 

    ln -s -f /usr/local/bin/python3.9 /usr/local/bin/python

    It might work. It did for me. You might have to change the link to python3.9 depending on your installation. 

    Steve

  • Remember this is all dependent on the how your PATH is configured.

  • Hi Peter,

    As I understand it,your operating system will first look for Python at /usr/local/bin. If it does not find it there, it will use the one from /usr/bin.

    You are not allowed to remove or overwrite your programs installed at /usr/bin.

    So for this workaround I suggest you try to link python3 to /usr/local/bin:

    ln -s -f <path_to_python3> /usr/local/bin/python

    It could be a good idea to screenshot the contents of /usr/local/bin before you do this, so you can revert to what you had in case you break something.

    Regards,
    Sigurd Hellesvik

  • Hi Everyone,

    Thanks for all your suggestions. 

    Below I include a transcript of what I've done. Unfortunately I'm still not able to get things to work.

    Here I show I'm using the zsh shell on my MacBook Pro running OS Monterey v12.0.1.

    % echo $0

    -zsh

    Next I display the PATH variable.

    % echo $PATH

    /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

    I confirmed there is no python file in /opt/homebrew/bin or /opt/homebrew/sbin.

     

    The location of python3 is /usr/bin/python3.

    % which python3

    /usr/bin/python3

    We see /usr/bin/python3 is not a link.  It's the actual binary.

    % ls -la /usr/bin/python3

    -rwxr-xr-x  1 root  wheel  137696 Oct 17 20:30 /usr/bin/python3

     

    Point /usr/local/bin/python to /usr/bin/python3.

    % sudo ln -s -f /usr/bin/python3 /usr/local/bin/python

    Open a new terminal window and confirm the link is correct.

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

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

    Confirm OS uses PATH to find python in /usr/local/bin/.

    % which python

    /usr/local/bin/python

    But when I run python -V I'm still getting v2.7.

    % python -V

    Python 2.7.18

    And when I start python from the command line I'm still getting v 2.7.

    % python

    WARNING: Python 2.7 is not recommended. 

    This version is included in macOS for compatibility with legacy software. 

    Future versions of macOS will not include Python 2.7. 

    Instead, it is recommended that you transition to using 'python3' from within Terminal.

    Python 2.7.18 (default, Oct  2 2021, 04:20:38) 

    [GCC Apple LLVM 13.0.0 (clang-1300.0.29.1) [+internal-os, ptrauth-isa=deploymen on darwin

    Type "help", "copyright", "credits" or "license" for more information.

    >>>

    And when I run /usr/local/bin/python -V I get v2.7.

    % /usr/local/bin/python -V

    Python 2.7.18

    But when I run /usr/bin/python3 -V I get v3.8.

    % /usr/bin/python3 -V

    Python 3.8.9

     

    I'm not sure what is going on.

     

  • Peter,

    You can not replace an executable with a symbolic link. You can use force to change a symbolic link to point else ware. It appears that /usr/local/bin/python is the v2.7 executable, not a link to the executable.

    Here is a thought. python3 is contained in the SDK installation under toolchain/bin. "python" does not exist in that directory. Change your path so /opt/nordic/ncs/v1.7.1/toolchain/bin is first. Create a python symbolic link here to python3 in that directory.

Related