简体   繁体   English

VS Code Python 安装和 Python 无法识别解释器

[英]VS Code Python installation and Python Interpreter not recognized

I am getting this message on the VS Code that "Python is not installed. Please download and install python before using the extension."我在 VS 代码上收到此消息"Python is not installed. Please download and install python before using the extension."

There is also no *"Python Interpreter"* to select. select 也没有*"Python Interpreter"* When I click on it it shows it empty.当我单击它时,它显示为空。

I do have Python and Python extension installed and I do have virtual environments set up in the Anaconda navigator but for some reason, I am not able to use them.我确实安装了PythonPython extension ,并且我在Anaconda navigator器中设置了virtual environments ,但由于某种原因,我无法使用它们。 I tried many ways like reinstalling the Python, Anaconda, and VS Code and also the Python extension for VS code but it's not solving the issue.我尝试了很多方法,例如重新安装 Python、Anaconda 和 VS 代码以及 Python 扩展,但它没有解决 VS 代码的问题扩展What could be the reason?可能是什么原因? I have attached a screenshot of the VS Code as well.我还附上了 VS Code 的屏幕截图。 Pleae click here to see the screenshot请点击这里查看截图

Thanks for your help.谢谢你的帮助。

You need to download the Python extension for VS Code.您需要下载 VS Code 的 Python 扩展。 https://marketplace.visualstudio.com/items?itemName=ms-python.python https://marketplace.visualstudio.com/items?itemName=ms-python.python

If you are still getting errors, I recommend to take a look here.如果您仍然遇到错误,我建议您在这里查看。 https://code.visualstudio.com/docs/python/python-tutorial#_prerequisites https://code.visualstudio.com/docs/python/python-tutorial#_prerequisites

I tried many methods but none worked.我尝试了很多方法,但都没有奏效。 So then I removed this extension "Anaconda Extension Pack by Microsoft" and it solved the issue.然后我删除了这个扩展"Anaconda Extension Pack by Microsoft" ,它解决了这个问题。 So anyone facing the same issue might try uninstalling this extension.因此,任何面临相同问题的人都可以尝试卸载此扩展程序。

I once faced similar problem and i found out that by default vs code looks for /usr/bin/python however in some cases on linux and mac the path is /usr/bin/python3 or 2, so you can fix it by declaring python3 as default version.我曾经遇到过类似的问题,我发现默认情况下 vs 代码查找 /usr/bin/python 但是在某些情况下在 linux 和 mac 路径是 /usr/bin/python3 或 2,所以你可以通过声明 python3 来修复它作为默认版本。

open terminal and type the following command打开终端并输入以下命令

sudo apt install python-is-python3

check the installation using -检查安装使用 -

python --version

it should give the output as 3.xx它应该将 output 作为 3.xx

I reinstalled VS Code as is - not changing existing libraries etc - and now VS Code recognises Python/ paths again.我按原样重新安装了 VS Code - 不更改现有库等 - 现在 VS Code 再次识别 Python/ 路径。 :) After updating to Windows 11 I think it just needed a refresh. :) 更新到 Windows 11 后,我认为它只需要刷新。

This is interpreter error.这是解释器错误。 you have to click on interpreter error showing bottom right in vs code then you choose installed latest python version.您必须单击显示在 vs 代码右下角的解释器错误,然后选择安装的最新 python 版本。 在此处输入图像描述

What did it for me was adding python to the environment variables (Windows).为我做的是将 python 添加到环境变量(Windows)中。

  • Find python at "C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe"在“C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe”中找到 python
  • Copy this path复制此路径
  • In the file explorer right click "This PC" and select properties在文件资源管理器中右键单击“此 PC”和 select 属性
  • Click Advanced System Settings in the settings window that will open (blue link on the right)点击将打开的设置window中的高级系统设置(右侧蓝色链接)
  • Select Environment Variable -> New -> Add the copied python path Select 环境变量 -> 新建 -> 添加复制的 python 路径

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

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