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!

Reply
  • 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!

Children
Related