您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何使Shebang能够在python3和python3.5之间选择正确的Python解释器

如何使Shebang能够在python3和python3.5之间选择正确的Python解释器

无需引入单独的shell和python脚本,单个文件可以兼而有之!

用以下顺序替换您的shebang行:

#!/bin/sh

# Shell commands follow
# Next line is bilingual: it starts a comment in Python, and is a no-op in shell
""":"

# Find a suitable python interpreter (adapt for your specific needs) 
for cmd in python3.5 python3 /opt/myspecialpython/bin/python3.5.99 ; do
   command -v > /dev/null $cmd && exec $cmd $0 "$@"
done

echo "OMG Python not found, exiting!!!!!11!!eleven" >2

exit 2

":"""
# PrevIoUs line is bilingual: it ends a comment in Python, and is a no-op in shell
# Shell commands end here
# Python script follows (example commands shown)

import sys
print ("running Python!")
print (sys.argv)
python 2022/1/1 18:39:51 有395人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶