pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Type of "bpy" is unknown

Open VimHax opened this issue 2 years ago • 5 comments

Environment data

  • Language Server version: 2022.7.20
  • OS and version: Fedora Linux 36
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.10.5

Code Snippet

import bpy

for area in bpy.context.screen.areas:
    print(area)

Repro Steps

  1. Follow this guide to build Blender as a Python module
  2. Install it globally
  3. Import bpy in a project

Expected behavior

Able to pick up at least some type information from the module. The module should be installed correctly as it can be imported from the interactive console. image

Actual behavior

The type of the whole module is marked as unknown. image

Logs

Logs

VimHax avatar Jul 12 '22 09:07 VimHax

I would try to launch the code to make sure your python environment sees it.

also recommend not installing things globally and to use a virtual environment.

bschnurr avatar Jul 12 '22 17:07 bschnurr

did we set correct python interpreter?

this one? image

heejaechang avatar Jul 12 '22 17:07 heejaechang

I have set the interpreter properly I believe. image image And yes the code does run fine when I execute it. (Assuming that's what you meant by asking to check whether the environment sees it) image

VimHax avatar Jul 12 '22 18:07 VimHax

FYI, if I disable the Pylance extension on VSC I also get basic autocomplete. image

VimHax avatar Jul 12 '22 18:07 VimHax

FYI, BPY is a native Python module. When installing the module it added bpy.so and a folder named 3.2 to the site-packages folder located at /usr/lib/python3.10/site-packages/.

VimHax avatar Jul 13 '22 19:07 VimHax

if bpy is a native module, it will need stubs ie. a .pyi file

bschnurr avatar Oct 13 '22 18:10 bschnurr

Closing old issue. As bschnurr mentions, this will need stubs from the python blender authors.

judej avatar Dec 04 '22 20:12 judej