简体   繁体   English

在带有 Python 扩展的 VS Code 中没有自动完成功能(使用 Pylance)

[英]No auto-completion in VS Code with Python extension (using Pylance)

I'm getting started with Python in VS Code.我开始在 VS Code 中使用 Python。 I've got the Python extension installed with IntelliSense from Pylance.我已经使用 Pylance 的 IntelliSense 安装了 Python 扩展。 Auto-completion has worked so far with some fairly simple pieces of code using built-in functions and methods, but now I'm playing with NumPy and auto-complete doesn't behave like I would expect.到目前为止,自动完成功能已经在一些相当简单的代码中使用了内置函数和方法,但现在我正在使用 NumPy 并且自动完成的行为不像我预期的那样。 I've got the following piece of code:我有以下代码:

import numpy as np

grid = np.arange(20).reshape(4, 5)

When typing "np."键入“np”时。 the auto-completion works perfectly, but when arriving at "np.arange(20)."自动完成工作完美,但到达“np.arange(20)”时。 nothing happens.什么都没发生。

What am I missing?我错过了什么? Thanks a lot!非常感谢!

Edited (additional info): works in other cases已编辑(附加信息):适用于其他情况
It does somehow work for this case:它确实适用于这种情况:

theta = np.linspace(0, np.pi, 3).<autocomplete works here>

Edited (additional info): differs per environment已编辑(附加信息):因环境而异
Apparently it differs per environment (I use Anaconda).显然它因环境而异(我使用 Anaconda)。

  • First screenshot: Python 3.9.7 + numpy 1.20.3 ('base')第一个屏幕截图:Python 3.9.7 + numpy 1.20.3 ('base')
  • Second screenshot: Python 3.10.4 + numpy 1.21.5 ('clean')第二个屏幕截图:Python 3.10.4 + numpy 1.21.5 ('clean')

Python 3.9.7 + numpy 1.20.3

Python 3.10.4 + numpy 1.21.5

It seem this issue is the same as this one .看来这个问题和这个问题一样。 Updating numpy to version >= 1.22 seems to fix it.将 numpy 更新到版本 >= 1.22 似乎可以解决它。

For context, Pylance uses Pyright under the hood to provide completions, and in this it's relying on typing information provided by numpy itself.对于上下文,Pylance 在后台使用 Pyright 来提供补全,在这方面它依赖于 numpy 本身提供的类型信息。 It looks like the newest versions of numpy has improved typing info, which solves the problem.看起来最新版本的 numpy 改进了输入信息,从而解决了这个问题。

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

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