如何告诉python脚本在python脚本中执行特定的python版本

问题描述

我的Jenkins正在使用python 2.7执行python脚本。但是我想使用python 3.7执行脚本。到目前为止,我已经做了类似的事情。

test.py

const uri = `mongodb://${username}:${password}@127.0.0.1/cloud?retryWrites=true&w=majority`;

我正在使用python test.py执行此脚本。在输出中,我正在获取python版本2.6。 谁能建议我如何使用python 3.7路径运行python脚本。

解决方法

如果要为每个命令选择版本,则可以使用以下命令行选项:

py -2 my_file.py
py -3 my_file.py
py -2.7 my_file.py
py -3.4 my_file.py