简体   繁体   中英

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

I'm getting started with Python in VS Code. I've got the Python extension installed with IntelliSense from Pylance. 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. I've got the following piece of code:

import numpy as np

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

When typing "np." the auto-completion works perfectly, but when arriving at "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).

  • First screenshot: Python 3.9.7 + numpy 1.20.3 ('base')
  • Second screenshot: 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.

For context, Pylance uses Pyright under the hood to provide completions, and in this it's relying on typing information provided by numpy itself. It looks like the newest versions of numpy has improved typing info, which solves the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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