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.

  • Linux Mint is based on Ubuntu, and specifically, Linux Mint 21.2 is based on Ubuntu 22.04 LTS, so I don't think this issue is specific to Linux Mint.

    Would you reconsider your support? Manual installation is not my preference, and I'd only use it as a last resort.

  • I can try to give you some questions which might figure out the issue.

    Lets start with: Which python version(s) do you have installed on your computer?

  • When googling the encoding error, it looks like it usually works to fix pythonpaths: https://stackabuse.com/bytes/resolving-modulenotfounderror-no-module-named-encodings-in-python/

    I suspect that the toolchain somehow uses your systems python instead of its own local version.
    In the Toolcahin Manager, can you click "Open Terminal" next to the toolchain version.
    Then in the terminal, use these two commands to try and see where python is set from:

    env
    whereis python

    You can also try to set $PYTHONPATH to make python point to the Toolchain Managers Python version.

  • 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

Reply Children
Related