emacs-lsp/lsp-pyright

Can not import cv2 correctly

binwan-dev opened this issue · 3 comments

I'm use pyrightconfig json file and install cv2.
Can't prompt correctly for cv2.imread or cv2.imwrite
Sorry, my english is not good.
我已经安装了cv2 包 在 test 环境下,并且使用了pyrightconfig.json 文件。
现在问题是无法正常提示cv2的候选项,例如 imread imwrite,这些都无法正常提示。
不过其他包(tensorflow numpy)都能正常提示
image

this is my pyrightconfig.json
image

this is lsp-log
image

Issue is here: microsoft/pylance-release#138

Now there are two solutions.

  1. compile the opencv from source
  2. If you have downloaded like pip install opencv-python then follow these two steps
    • pip install mypy
    • stubgen -m cv2 -o {cv2-package-folder} (In my case it is /home/soumya/anaconda3/lib/python3.7/site-packages/cv2)

I have tested the step 2 and it works.

I needed to modify the stubgen command for this to work.

cd {to your cv2 directory}
stubgen -m cv2 -o .
mv cv2.pyi __init__.pyi

M-x lsp-restart-workspace

It work, Thanks! I'll close this issue