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?

  • This looks like a path issue.

    Can you do the following commands?

    python --version
    python --version
    whereis python
    whereis python3
    echo $PATH
    

    Which operating system do you use?

    Which version of the Toolchain Manager do you use?

    Regards,
    Sigurd Hellesvik

  • Hi Sigurd,

    There you go:

    python --version
    Python 3.8.2
    
    python3 --version
    Python 3.8.2
    
    whereis python
    python: /usr/bin/python /home/guilherme/ncs/toolchains/v2.3.0/usr/local/bin/python /usr/share/man/man1/python.1.gz
    
    whereis python3
    python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3 /home/guilherme/ncs/toolchains/v2.3.0/usr/local/bin/python3 /usr/share/man/man1/python3.1.gz
    
    echo $PATH
    /home/guilherme/ncs/toolchains/v2.3.0/usr/bin:/home/guilherme/ncs/toolchains/v2.3.0/usr/bin:/home/guilherme/ncs/toolchains/v2.3.0/usr/local/bin:/home/guilherme/ncs/toolchains/v2.3.0/opt/bin:/home/guilherme/ncs/toolchains/v2.3.0/opt/nanopb/generator-bin:/home/guilherme/ncs/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/bin:/home/guilherme/.nvm/versions/node/v18.11.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/guilherme/.dotnet/tools:/home/guilherme/.local/bin

    I am on Ubuntu 22.04, using nRF Connect 4.0.1 and Toolchain Manager 1.2.4.

    I stopped having the problem, though. I think it might have something to do with exporting and running the env.sh from the toolchain manager.

    My colleagues had the same issue, and one of them made it go away by unsetting the PYTHONHOME variable after opening the terminal from the Toolchain Manager.

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

Related