在 Node 中更改生成脚本的 Python 版本

Change Python version for spawned script in Node

在 index.ts 中,我在脚本中生成了 child_process,我想知道如何指定哪个 Python 版本应该是 运行,因为它默认为 2.7(我的 mac 附带的那个),而不是 Python 3.9.6(64 位),这是我在 vscode.[=14= 中选择的解释器]

import { spawnSync } from 'child_process';

const write_questions = spawnSync('python', ['src/write_questions.py', subject], {stdio: 'inherit'})

这个命令不起作用,因为 Python 版本已经过时并且不包括 f-strings,但是,它确实适用于我的另一个 machine,根本没有 2.7 :

basic_addition_file.write(f"What is {basic_addition_first} + {basic_addition_second}?: \ {basic_addition_answers}")

检查python版本的结果:

print(sys.version)

2.7.16 (default, Jun 18 2021, 03:23:53)

我刚刚在 mac 上更改了我的默认 python 版本,这在过去从来都不是问题,因为我总是可以 select 我喜欢的 Python 解释器VSCode 但是为此,必须这样做。所以现在当我在我的终端中输入 Python 时:

python
Python 3.9.6 (default, Jul 28 2021, 13:42:40) 
[Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

打印sys.version的结果:

python write_questions.py
3.9.6 (default, Jul 28 2021, 13:42:40) 
[Clang 12.0.5 (clang-1205.0.22.11)]