Is there a standard way to make sure that a python script will be interpreted by python3 and not python2?

Related: Is there a standard way to make sure that a python script will be interpreted by python2, not python3?

Apparently, not all distributions come with a symlink python3. #!/usr/bin/env python3raises a no-such-file-or-directory error. Which shebang line should I use if my script requires any version of Python 3?

+4
source share
1 answer
import sys
try:
   assert sys.version_info[0] == 3
except:
   print "ERROR NOT PYTHON 3!"
   sys.exit()
+2
source

All Articles