Versions:
FreeBSD 13.1-RELEASE
Python 3.9.16
Paths
echo $PATH
:
/home/user/.cargo/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/user/bin
Code:
if shutil.which("rustc") is not None:
try:
rustc_output = subprocess.run(
["rustc", "--version"],
capture_output=True,
timeout=0.5,
encoding="utf8",
check=True,
).stdout
version = re.sub("^rustc ", "", rustc_output.strip())
print(version)
print("wow")
except Exception as e:
print("well OK")
print(e)
else:
print("OK NO")
Info and expectations
Running:
python3 -c "print(__import__('os').environ.get('PATH', None))"
returns:
/home/user/.cargo/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/user/bin
When I use pdb
to step through I notice that shutil.which() steps through various posix paths but never looks in the ~/.cargo/bin even though it is readily available in my shell cli.
Any insight available? Thank you.