Python Visual Studio Code:Intellisense 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50389852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:28:48  来源:igfitidea点击:

Visual Studio Code: Intellisense not working

pythondjangovisual-studio-code

提问by Donovan Keating

My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with Ctrl + Shift, it only displays a loading message. I'm using Python (with Django) and have installed ms-python.python. I also have Djaneiro. It is still not working. enter image description here

我的 Visual Studio Code 的 Intellisense 无法正常工作。每次我尝试将它与 一起使用时Ctrl + Shift,它只显示一条加载消息。我正在使用 Python(带有 Django)并且已经安装了ms-python.python. 我也有Djaneiro。它仍然无法正常工作。 在此处输入图片说明

What seems to be the problem here?

这里似乎有什么问题?

回答by Jerin

This can be caused by many reasons, some of them are as follows.

这可能由多种原因引起,其中一些原因如下。

1)Python executable path in VS code is incorrect

1)VS代码中Python可执行路径不正确

Solution: Configure the path to the python executable in the settings.json


Remember to re start VS Code once done.

2)The custom module is located in a non-standard location

2)自定义模块位于非标准位置

Solution: Configure the settings.json to include this custom location for autocompletion to work

An exmample settings.json (for Linux) used to add a customModule from workspaceFolder

{

    "python.pythonPath": "/usr/bin/python",
    "python.autoComplete.extraPaths": [

       "${workspaceFolder}/customModule"
    ]
}


Remember to re start VS Code once done.

3) VS Code was not launched from the active virtual environment

3) VS Code 未从活动虚拟环境启动

The path to the custom modules is set when a virtual environment is activated.
Solution: Launch VS Code from a Terminal/Command window with the correct virtual environment activated

回答by Ehsan Ahmadi

First of all if you've installed virtualenv on your project run vscode from there. Then in your vscode settings, i mean settings.json, you can follow my configuration or trace in which one you have a problem. Most of time this problem stem from putting incorrect path in pythonPath setting

首先,如果您在项目中安装了 virtualenv,请从那里运行 vscode。然后在你的 vscode 设置中,我的意思是 settings.json,你可以按照我的配置或跟踪你有问题的地方。大多数情况下,这个问题源于在 pythonPath 设置中放置了不正确的路径

    {
  "python.pythonPath": "${workspaceFolder}/env/bin/python3",
  "editor.formatOnSave": true,
  "python.linting.pep8Enabled": true,
  "python.linting.pylintPath": "pylint",
  "python.linting.pylintArgs": ["--load-plugins", "pylint_django"],
  "python.linting.pylintEnabled": true,
  "python.linting.pep8Args": ["--ignore=E501"],
  "files.exclude": {
    "**/*.pyc": true
  }
}

Update:

更新:

If you want to have a well-configuration of Vscode That i personally use for developing my Django and React web-applications you can glance this.

如果你想有Vscode的精心配置,我个人用于开发我的Django和阵营就可以一览无余Web应用

回答by rogers.wang

i change change the :jedi true 2 false, or flase 2 true, when reload the VSCode, that's ok.

我改变改变:jedi true 2 false,或flase 2 true,当重​​新加载VSCode时,没关系。

my setting:

我的设置:

{
    "editor.fontSize": 16,
    "explorer.confirmDragAndDrop": false,
    "extensions.autoUpdate": false,
    "workbench.colorTheme": "Default Dark+",
    "editor.fontFamily": "Consolas, Dengxian",
    "workbench.sideBar.location": "left",
    "workbench.startupEditor": "newUntitledFile",
    "workbench.iconTheme": "material-icon-theme",
    "python.pythonPath": "d:\Source\Django\Scripts\python.exe",
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "git.ignoreLimitWarning": true,
    "python.jediEnabled": true,
    "python.autoComplete.extraPaths": [
        "d:\Source\Django\",
    ],
    "python.autoComplete.addBrackets": true
}

回答by Victor

"If you find IntelliSense has stopped working, the language service may not be running. Try restarting VS Code and this should solve the issue." From https://code.visualstudio.com/docs/editor/intellisenseand helped to me

“如果您发现 IntelliSense 停止工作,则语言服务可能未运行。尝试重新启动 VS Code,这应该可以解决问题。” 来自https://code.visualstudio.com/docs/editor/intellisense并帮助了我

回答by Macdara.Dev

My settings were all in order, but still not auto-completing in-line. I disabled the Kite extension & a couple of other ones that I didn't really need, & IntelliSense started auto-completing. Not 100% sure, but I reckon it might have been my "Kite" extension settings that were getting in the way.

我的设置都井井有条,但仍然没有自动完成在线。我禁用了 Kite 扩展和其他几个我并不真正需要的扩展,并且 IntelliSense 开始自动完成。不是 100% 确定,但我认为这可能是我的“风筝”扩展设置造成的。

回答by V Reddy

I had this issue for a while now. I tried a lot of solutions from stack but none worked. Uninstallingall the extensions did the trick for me.

我有一段时间有这个问题了。我从堆栈中尝试了很多解决方案,但没有一个奏效。卸载所有扩展对我来说很有效。

回答by alshafi

I was also facing this problem and it's really annoying. This is a major bug of VS code that happens with installing some of the npm packages. VS code IntelliSense crashes and stops working after a few moments you start the VScode due to unsuccessful loading of the modules of the new package.

我也遇到了这个问题,真的很烦。这是安装一些 npm 包时发生的 VS 代码的一个主要错误。由于新包的模块加载失败,VS code IntelliSense 在您启动 VScode 片刻后崩溃并停止工作。

In my case, it was solved by using the VScode insiders version:https://code.visualstudio.com/insiders/

就我而言,它是通过使用 VScode 内部人员版本解决的:https ://code.visualstudio.com/insiders/

Download and install VScode insiders, install all the extension you use and then check if the problem is fixed.

下载并安装 VScode 内部人员,安装您使用的所有扩展,然后检查问题是否已修复。

回答by 143560

If you've tried everything but still if it doesn't work, in my case installing the extension Visual Studio IntelliCodewith the Pythonextension worked.

如果您已经尝试了所有方法但仍然无法正常工作,那么在我的情况下,使用Python扩展安装扩展Visual Studio IntelliCode可以正常工作。

回答by Phani Kumar

For any IDE getting Intellisense for dynamically typed language is not possible.

对于任何为动态类型语言获取 Intellisense 的 IDE 都是不可能的。

I see that modelis dynamically initialized where IntelliSense can't guess the correct type of the object. For any static typed like C++ or Java, this wouldn't be the case but python is dynamically typed so IntelliSense, not always works as expected.

我看到模型是动态初始化的,其中 IntelliSense 无法猜测对象的正确类型。对于像 C++ 或 Java 这样的任何静态类型,情况并非如此,但 python 是动态类型的,因此 IntelliSense 并不总是按预期工作。