简体   繁体   English

Visual Studio 不会更改为正确的 Python 版本

[英]Visual studio not changing to correct python version

I am trying to change the python version on visual studio code from 2.7.10 to Python 3.8.1.我正在尝试将 Visual Studio 代码上的 Python 版本从 2.7.10 更改为 Python 3.8.1。

If I click on the python interpreter it says I am using Python 3.8如果我点击 python 解释器,它会说我使用的是 Python 3.8

在此处输入图片说明

Then if I check the version in the terminal it also says然后,如果我检查终端中的版本,它也会说

在此处输入图片说明

To change the Python interpreter first I changed the JSON settings file要首先更改 Python 解释器,我更改了 JSON 设置文件

    "python.pythonPath": "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8"

and then I ran these commands in the terminal because after this the terminal still was running on 2.7.10.然后我在终端中运行了这些命令,因为在此之后终端仍然在 2.7.10 上运行。

 echo $SHELL echo $PATH alias python=/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8

Now both the terminal and visual studio seem to be running on 3.8 but I can't use the new f string format现在终端和 Visual Studio 似乎都在 3.8 上运行,但我不能使用新的 f 字符串格式

print(f'hi {myVariable}')

but I can still use但我仍然可以使用

print('hi {}'.format(myVariable)) 

I printed out the sys version, but the file is still using the old python, how do I change it to use the new one?我打印了sys版本,但是文件还在使用旧的python,我如何更改它以使用新的?

import sys; 
print(sys.version)

output: 2.7.10 (default, Feb 22 2019, 21:55:15) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)]输出:2.7.10(默认,2019 年 2 月 22 日,21:55:15)[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)]

Try running your files using the python3 command instead of python so.. instead of尝试使用python3命令而不是python来运行你的文件,所以......而不是

python test.py

you do你做

python3 test.py

(this is assuming that you manually run the python file from the terminal) (这是假设您从终端手动运行 python 文件)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM