pythonpython-3.8system-paths

Python3.8 cannot find command in the PATH env var (Ubuntu)


When running a python script using python38 it gives:

FileNotFoundError: [Errno 2] No such file or directory: 'riscv32-unknown-elf-objdump'

'riscv32-unknown-elf-objdump' is on my $PATH at shell command line, and also on sys.path printed by the python script itself.

If I switch to python3, then this error goes away. The python line producing the error:

result = subprocess.run(["riscv32-unknown-elf-objdump", "-S", "-M", "numeric", exe_file], stdout=PIPE, stderr=PIPE, encoding="ASCII")

Any hints? Edit: The version is defined in the script header, e.g. #!/usr/bin/env python38


Solution

  • The way I found to solve this is to add shell=True in the call of subprocess:

    result = subprocess.run(["riscv32-unknown-elf-objdump", "-S", "-M", "numeric", exe_file], stdout=PIPE, stderr=PIPE, encoding="ASCII",shell=True)

    Still no idea why this is required for python3.8 and not earlier versions.