Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not import cv2 correctly #41

Closed
binwan-dev opened this issue Mar 25, 2021 · 3 comments
Closed

Can not import cv2 correctly #41

binwan-dev opened this issue Mar 25, 2021 · 3 comments

Comments

@binwan-dev
Copy link

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

@Blade6570
Copy link

Blade6570 commented Apr 5, 2021

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.

@steepestascent
Copy link

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

@binwan-dev
Copy link
Author

It work, Thanks! I'll close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants