gpt4 book ai didi

python - VSCODE - 如何选择远程 ssh 的 python 版本?

转载 作者:行者123 更新时间:2023-12-05 04:35:11 24 4
gpt4 key购买 nike

如何通过 vscode 使用远程 ssh 执行 python 3.9?

当我连接到服务器时,它只以 2.6 运行

我的代码:

from platform import python_version

print("Current Python Version-", python_version())

输出:

[Running] python -u "/root/python/projetos.py"
('Current Python Version-', '2.6.6')

有没有办法通过vscode选择python版本?我尝试在 Linux 级别进行更改(使用 alternative 命令),但没有成功。

我需要的是 vscode 来调用 python3.9 命令而不是 python 命令:

[root@quickstart ~]# python --version
Python 2.6.6
[root@quickstart ~]# python3.9 --version
Python 3.9.10
[root@quickstart ~]#

最佳答案

我发现了。

需要在远程ssh服务器上安装python vscode扩展。

当连接到 SSH 服务器时,在扩展中(Ctrl + shift + x),寻找 python 等,在 SSH 中安装:

enter image description here

安装后,键入 Ctrl + shift + p 并查找 Python: select interpreter.

enter image description here

此处将显示服务器上安装的所有 python 解释器路径。

enter image description here

关于python - VSCODE - 如何选择远程 ssh 的 python 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71066180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com