Shebang/选择脚本将运行的 Python 版本 [英] Shebang/choose what version of Python a script is going to run

查看:58
本文介绍了Shebang/选择脚本将运行的 Python 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为很多人,我同时拥有 2.7 和 3.5 版本的 python.有些代码是向后兼容的,有些则不是.这是因为缺少 2.7 而不是 3.5 的模块.因此,我有相当多的 2.7 和相当多的 3.5 脚本..py 扩展名的默认值是我电脑中的 3.5 版本的 python.我的问题如下:你怎么能告诉"脚本使用另一个版本的python(例如2.7)而不是我使用的默认值(3.5).我听说过 Shebang,但它只是 Linux.

As a lot of people I have both the 2.7 and 3.5 version of python. Some code is backwards-compatible, some are not. This is because of the lack of modules that exist for 2.7 but not for 3.5. I therefore have a fair bit of scripts that are 2.7 and a fair bit that are 3.5. The default of .py extensions is the 3.5 version of python in my computer. My question is as follows: How can you "tell" the script to use another version of python(2.7 for instance) rather than the default I am using(3.5). I heard about Shebang, but it is Linux only.

推荐答案

如 JF Sebastian 对 此答案 的评论中所述,Python Launcher for Windows 可以选择从 shebang 行运行的 Python 版本.根据文档,它默认安装在 Python 3.3 及更高版本中.

As mentioned in J. F. Sebastian's comment on this answer, the Python Launcher for Windows can select the Python version to run from a shebang line. According to the docs it's installed by default with Python 3.3 and later.

这篇关于Shebang/选择脚本将运行的 Python 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆