简体   繁体   中英

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

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

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

import sys
try:
   assert sys.version_info[0] == 3
except:
   print "ERROR NOT PYTHON 3!"
   sys.exit()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM