nRF Connect SDK: ModuleNotFoundError: No module named 'encodings'

Hi,

I am using the nRF Connect SDK 2.3.0 and running into an issue when calling python from the terminal opened from the Toolchain Manager (via the Open Terminal option).

Calling `python` from this terminal gives me the following error:

Python path configuration:
  PYTHONHOME = '/home/guilherme/ncs/toolchains/v2.3.0/usr/local'
  PYTHONPATH = '/home/guilherme/ncs/toolchains/v2.3.0/usr/local/lib/python3.8/site-packages'
  program name = 'python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/usr/bin/python'
  sys.base_prefix = '/home/guilherme/ncs/toolchains/v2.3.0/usr/local'
  sys.base_exec_prefix = '/home/guilherme/ncs/toolchains/v2.3.0/usr/local'
  sys.platlibdir = 'lib'
  sys.executable = '/usr/bin/python'
  sys.prefix = '/home/guilherme/ncs/toolchains/v2.3.0/usr/local'
  sys.exec_prefix = '/home/guilherme/ncs/toolchains/v2.3.0/usr/local'
  sys.path = [
    '/home/guilherme/ncs/toolchains/v2.3.0/usr/local/lib/python3.8/site-packages',
    '/home/guilherme/ncs/toolchains/v2.3.0/usr/local/lib/python310.zip',
    '/home/guilherme/ncs/toolchains/v2.3.0/usr/local/lib/python3.10',
    '/home/guilherme/ncs/toolchains/v2.3.0/usr/local/lib/python3.10/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007f6c65212740 (most recent call first):
  <no Python frame>

If I use python3 instead of python, it works as expected. This causes me more trouble down the line because I have a west extension that uses subprocess.Popen() and I run into the exact same error trace.

What might be causing this and how do I solve the problem?

Parents
  • I have the same issue, which breaks the build process.

    I'm using the nRF Connect SDK 2.4.1 on Linux Mint 21.2. In Toolchain Manager, I open the terminal for nRF Connect SDK v2.4.1, then:

    $ python
    Python path configuration:
      PYTHONHOME = '/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local'
      PYTHONPATH = '/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local/lib/python3.8/site-packages'
      program name = 'python'
      isolated = 0
      environment = 1
      user site = 1
      import site = 1
      sys._base_executable = '/usr/bin/python'
      sys.base_prefix = '/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local'
      sys.base_exec_prefix = '/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local'
      sys.platlibdir = 'lib'
      sys.executable = '/usr/bin/python'
      sys.prefix = '/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local'
      sys.exec_prefix = '/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local'
      sys.path = [
        '/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local/lib/python3.8/site-packages',
        '/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local/lib/python310.zip',
        '/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local/lib/python3.10',
        '/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local/lib/python3.10/lib-dynload',
      ]
    Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
    Python runtime state: core initialized
    ModuleNotFoundError: No module named 'encodings'
    
    Current thread 0x00007f437c825280 (most recent call first):
      <no Python frame>
      
    $ python --version
    Python 3.10.12
    
    $ python3 --version
    Python 3.8.2
    
    $ whereis python
    python: /usr/bin/python /usr/share/python /usr/share/man/man1/python.1.gz
    
    $ whereis python3
    python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3 /home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local/bin/python3 /usr/share/man/man1/python3.1.gz
    
    $ echo $PATH
    /home/laci/projects/ncs/toolchains/1f9b40e71a/usr/bin:/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/bin:/home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local/bin:/home/laci/projects/ncs/toolchains/1f9b40e71a/opt/bin:/home/laci/projects/ncs/toolchains/1f9b40e71a/opt/nanopb/generator-bin:/home/laci/projects/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk/aarch64-zephyr-elf/bin:/home/laci/projects/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk/x86_64-zephyr-elf/bin:/home/laci/projects/ncs/toolchains/1f9b40e71a/opt/zephyr-sdk/arm-zephyr-eabi/bin:/tmp/.mount_nrfcongdGUKx:/tmp/.mount_nrfcongdGUKx/usr/sbin:/home/laci/.nvm/versions/node/v16.13.0/bin:/home/laci/.local/bin:/home/laci/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/laci/bin:/usr/local/bin:/sbin:/usr/sbin:/home/laci/.local/bin:/home/laci/bin:/usr/local/bin:/sbin:/usr/sbin:/home/laci/.local/bin:/home/laci/bin:/usr/local/bin:/sbin:/usr/sbin:/home/laci/.local/bin:/home/laci/bin:/usr/local/bin:/sbin:/usr/sbin:/home/laci/.local/bin
    laci@lian:~/projects/ncs/v2.4.1$ 
    

    I want to refrain from manual installation and would much rather rely on the Toolchain Manager to install further SDK versions easily.

    Thanks in advance for your help!

  • mlac said:
    I'm using the nRF Connect SDK 2.4.1 on Linux Mint 21.2

    Here are a list of the operating systems we officially support for our tooling: Supported operating systems.

    Because of this, we can not guarantee that the Toolchain Manager works on Mint, and I can not assist much.
    However, the manual install should still work fine. I also run on a Linux distro other than Ubuntu and I the manual install works fine for me.

    I have created an unofficial experimental installer script at https://gitlab.com/hellesvik/nrf-connect-sdk-installer, which does manual installation steps (except for pip requirements) for you.
    If you want you can try this.

  • mlac said:

    I've already provided what you're asking in my first comment above.

    PYTHONPATH is /home/laci/projects/ncs/toolchains/1f9b40e71a/usr/local/lib/python3.8/site-packages

    Ah, I missed that.

    From your logs, do I understand it correctly that you get the error when you just type "python" inside that terminal?
    Do you also get the same error when trying to build a project using VS Code or west?

  • Yes, I get the encoding error by simply invoking "python" from the nRF terminal but not by invoking python3.

    I also get the error when trying to build the project using VS Code or west. (I open VS Code and the terminal from the toolchain manager.)

  • This case looks very similar:  nRF Connect Toolchain fails

    Does the answers in this case help?

  • When I try the solution contained in the referenced thread, I get the following error:

    The relevant setting that I set:

  • At this point, I think I can not say anything more that:

    Linux Mint is not something we have official support for in the Toolchain Manager, so we can not guarantee that it works.
    I suggest the manual installation as an alternative

Reply Children
Related