I have a centos 7 VM and I need sudo permissions to run certain shell commands in a python script. I have a #!/usr/bin/env python3.7
at the top of my script and running it as sudo ./script.py
gives me a /usr/bin/env: python3.7: No such file or directory
error. How do I run my code as sudo? Just to clarify, it does run if I simply enter ./script.py
, but I get a permission denied
when the script tried to execute 3 specific commands hence the need for sudo.
echo $PATH
result:
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/centos/.local/bin:/home/centos/bin:/home/centos/.local/bin:home/centos/bin
sudo echo $PATH
gives the same result as above.
type python3.7
gives me: python3.7 is /usr/local/bin/python3.7
PATH
includespython3.7
whereas thePATH
ofroot
does not. Tryecho $PATH
andsudo echo $PATH
to confirm, they should contain the output oftype python3.7
$PATH
expanded by the shell beforesudo
is even run? (@BloodLord:#!/bin/env /usr/local/bin/python3.7
should work for the moment, in particular if you're not worried about cross-distro compatibility, even if it's not the nicest solution.)sudo sh -c 'echo $PATH'
? Also, @UlrichSchwarz probably meant#!/usr/local/bin/python3.7
and not#!/bin/env /usr/local/bin/python3.7
.