Skip to main content
 首页 » 编程设计

python之你如何找出你的 python 解释器在 python 中的位置

2025年05月04日14dflying

我的系统有很多版本的 python。有些是 32b,有些是 64b,有些是 2.4,有些是 2.7,等等。我正在使用一个需要运行另一个 python 脚本的 python 脚本。我想使用与运行初始脚本时相同版本的 python 运行第二个脚本。

我的计划是做这样的事情:

os.system('%s script.py' % currentPython) 

问题是:如何定义“currentPython”?

请您参考如下方法:

python 解释器的路径可访问为 sys.executable .

请使用subprocess模块调用子解释器,而不是 os.system()。