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

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

Children
No Data
Related