It goes the other way round. If you're already running python 2, sys.executable
is the path to the python 2.7 executable. If you're already running python 3, sys.executable
is the path to the python 3.4 executable. If you want to run a script with python 3.4, use the command
python3 myscript.py
in a terminal, or use a shebang line
#!/usr/bin/env python3
at the top of your file and simply call ./myscript.py
(without the command python
).