简体   繁体   English

Visual Studio Code 和 PowerShell 无法识别新的 Python 版本

[英]Visual Studio Code and PowerShell do not identify new Python version

On Windows 10, I want to use Python 3.8, which I installed and downloaded.在 Windows 10 上,我想使用我安装并下载的 Python 3.8。

However, in Visual Studio Code, the cmd -environment, and PowerShell, the command python returns 3.5.6, an Anaconda install.但是,在 Visual Studio Code、 cmd -environment 和 PowerShell 中,命令python返回 3.5.6,Anaconda 安装。

In particular, the screenshot shows that (at the bottom left) the active interpreter should be 3.8.1;特别是,屏幕截图显示(在左下角)活动解释器应该是 3.8.1; and the "Python Path" in the settings also directs to the correct path, but typing python in Terminal just outputs 3.5.6.并且设置中的“Python 路径”也指向正确的路径,但在终端中输入python只会输出 3.5.6。

VS 代码截图

In the PATH -variable, I deleted the line that points to 3.5.6's directory, and added the directory of 3.8.1 (was done automatically during the install):PATH变量中,我删除了指向 3.5.6 目录的行,并添加了 3.8.1 目录(在安装过程中自动完成):

在此处输入图片说明

What more do I need to do?我还需要做什么?


Edit 1编辑 1

Environment Variables are:环境变量是:

Path: C:\\Users\\d91776\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts\\;C:\\Users\\d91776\\AppData\\Local\\Programs\\Python\\Python38-32\\;%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files\\java\\jdk\\bin;C:\\Program Files\\Java\\jdk1.8.0_191\\bin;C:\\Program Files\\Java\\jre1.8.0_191\\bin;C:\\Users\\d91776\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\d91776\\Desktop\\Selenium Markitwire\\geckodriver-v0.24.0-win64;C:\\Users\\d91776\\AppData\\Local\\Google\\Cloud SDK\\google-cloud-sdk\\bin;路径: C:\\Users\\d91776\\AppData\\Local\\Programs\\Python\\Python38-32\\Scripts\\;C:\\Users\\d91776\\AppData\\Local\\Programs\\Python\\Python38-32\\;%USERPROFILE%\\AppData\\ Local\\Microsoft\\WindowsApps;C:\\Program Files\\java\\jdk\\bin;C:\\Program Files\\Java\\jdk1.8.0_191\\bin;C:\\Program Files\\Java\\jre1.8.0_191\\bin;C: \\Users\\d91776\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\d91776\\Desktop\\Selenium Markitwire\\geckodriver-v0.24.0-win64;C:\\Users\\d91776\\AppData\\Local\\Google\\ Cloud SDK\\google-cloud-sdk\\bin;

PSModulePath: %HomeDrive%%HomePath%\\Documents\\WindowsPowerShell\\Modules;C:\\Users\\d91776\\AppData\\Local\\Google\\Cloud SDK\\google-cloud-sdk\\platform\\PowerShell PSModulePath: %HomeDrive%%HomePath%\\Documents\\WindowsPowerShell\\Modules;C:\\Users\\d91776\\AppData\\Local\\Google\\Cloud SDK\\google-cloud-sdk\\platform\\PowerShell

TEMP and TMP: are both %USERPROFILE%\\AppData\\Local\\Temp TEMPTMP:都是 %USERPROFILE%\\AppData\\Local\\Temp

There is another "Path" in System variables, but I cannot display it as text.系统变量中还有另一个“路径”,但我无法将其显示为文本。 But it does not seem to related to the python paths.但它似乎与 python 路径无关。 See highlighted section in Screenshot:请参阅屏幕截图中突出显示的部分:

在此处输入图片说明


Edit 2编辑 2

In Anaconda, I deactivated the one additional environment that had Python version 3.5.6.在 Anaconda 中,我停用了具有 Python 版本 3.5.6 的另一个环境。

However, the problem now persists with Python version 3.7.3 (version of Python displayed upon typing python in terminal) and 3.8.1 (selected in VS Code as Python interpreter, and displayed in the bottom-left, just as in the above screenshot).但是,问题现在仍然存在于 Python 版本 3.7.3(在终端中键入python时显示的 Python 版本)和 3.8.1(在 VS Code 中选择为 Python 解释器,并显示在左下角,就像上面的截图一样)。

C:\>python
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.

The Python extension for VS Code does not influence what the python command points at; VS Code 的 Python 扩展不会影响python命令指向的内容; that comes down to your PATH environment variable.这归结为您的PATH环境变量。 If you want to manually launch Python 3.8 then you should run python3.8 or py -3.8 (if you just want the newest Python 3 installed then change that to python3 or py -3 ).如果您想手动启动 Python 3.8,那么您应该运行python3.8py -3.8 (如果您只想安装最新的 Python 3,则将其更改为python3py -3 )。 Otherwise create a virtual environment with Python 3.8 and when it's activated python will be Python 3.8.否则使用 Python 3.8 创建一个虚拟环境,当它被激活时, python将是 Python 3.8。

As for why this doesn't work in PowerShell, it's possible the install of Python 3.8 that you used installed a python command for Python 3.8 (you would have to check those directories on your PATH to verify this).至于为什么这在 PowerShell 中不起作用,您使用的 Python 3.8 的安装可能为 Python 3.8 安装了python命令(您必须检查PATH上的这些目录以验证这一点)。

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

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