`sudo pythonX.Y` invokes a wrong Python executable

I try to use python3.7 like it is describe in that comment, but that does not work for sudo.

Fort running non-sudo commands, I correctly use python3.7. But for sudo-commands python is still python2.7 and python3 is still python3.5.

0.00s$ python --version
Python 3.7.1
The command "python --version" exited with 0.
0.00s$ python3 --version
Python 3.7.1
The command "python3 --version" exited with 0.
0.02s$ sudo python --version
Python 2.7.12
The command "sudo python --version" exited with 0.
0.01s$ sudo python3 --version
Python 3.5.2
The command "sudo python3 --version" exited with 0.

How is python3.7 correctly used as sudo on travis on the linux image?

Try

sudo $(which python)

You probably shouldn’t be running it with sudo anyway.

Our jobs set up Python run time environment for the user travis, not for root. sudo -E (https://www.unix.com/man-page/Linux/8/sudo/) may help.