-
Notifications
You must be signed in to change notification settings - Fork 767
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
Classes for opencv-python are not detected and break intellisense autocomplete #3976
Comments
This is a duplicate of #138. |
I don't think so. I read this before posting an issue. The issue is NOT having "cv2." autocomplete, but any classes INSIDE cv2 do not have autocompletion nor class typing. All the "fixes" mentioned there don't fix the issue I am having. I have never needed any "fixes" or anything for pycharm to do the same thing either. This is definitely a VS Code issue. |
Which workarounds have you tried? Have you generated your own local type stubs for PyCharm will extract minimal type information out of a binary library like cv2. It does so by loading (and therefore executing) the library and then using reflection to extract classes, methods, etc. Pylance does not do this for security and performance reasons. You would need to do this manually using a tool like stubgen to extract the type information. |
Here is what I have done: And there is still no autocomplete for the classes inside cv2. I also tried copying the file it generates into multiple different locations. I even added the location for the pyi to the extrapaths in the python extension settings. |
Once you generate the type stubs via stubgen, you need to move them into a project-local directory called |
Is there a solution that is not project dependent? Would be very annoying if I have to do this for every single project. I would like it to stay this way for the interpreter that Pylance is set to. |
The best solution is for the maintainers of opencv to include type stubs with their library. The next best solution is for someone to publish a "cv2-stubs" stub package on pypi that includes type stubs for opencv. This could then be installed in your python environment and used for all of your projects. You could check with the maintainers of typeshed to see if they'd be interested in including stubs for cv2. Then you could contribute yours as a starting point. |
How could I publish a cv2-stubs package myself? For example, how could I go about getting this working on my own local machine, then share it with others? Would I be able to use the init.pyi file to do this? |
Thanks my friend! I shall look into this! |
videoReader: cv2.VideoCapture = cv2.VideoCapture(videoFileLocation) fps = int(videoReader.
After typing the "dot" after the "videoReader" variable, there is no autocompletion. After hovering over "cv2.VideoCapture", it shows "Any" as class type.
The text was updated successfully, but these errors were encountered: