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

无人久伴 提交于 2019-12-05 01:57:54

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/19625768/is-there-a-standard-way-to-make-sure-a-python-script-will-be-interpreted-by-pyth

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!