Skip to content

os.execl fails to execute Python #713

@alexyao2015

Description

@alexyao2015

From a python script, attempting to run os.execl with Python as the executable fails because Python seems to locate /install as its path instead of the real path. This installation was installed using uv, but I'm still experiencing this issue.

In the real world, this affects the yocto poky project which works fine with other Python distributions but fails to run with this one.

Example:

import sys
import os

os.execl(sys.executable, "test")

Output:

$ python test.py
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'test'
  isolated = 0
  environment = 1
  user site = 1
  safe_path = 0
  import site = 1
  is in build tree = 0
  stdlib dir = '/install/lib/python3.11'
  sys._base_executable = '/usr/bin/test'
  sys.base_prefix = '/install'
  sys.base_exec_prefix = '/install'
  sys.platlibdir = 'lib'
  sys.executable = '/usr/bin/test'
  sys.prefix = '/install'
  sys.exec_prefix = '/install'
  sys.path = [
    '/install/lib/python311.zip',
    '/install/lib/python3.11',
    '/install/lib/python3.11/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 0x00007f997d316740 (most recent call first):
  <no Python frame>

Using another python distribution (e.g. from Ubuntu or PyEnv) that has the correct compiled in paths:

$ python test.py 
Python 3.11.9 (main, Jan  8 2025, 12:47:30) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions