pylance-release
pylance-release copied to clipboard
intellisense cv2 (OpenCV-Python) does not work
VS Code version
1.62.0
Extension version
v2021.11.1422169775
OS type
Linux
OS version
Manjaro
Python distribution
Operating system
Python version
3.9.7 64-bit
Language server
Pylance
Expected behaviour
When I enter cv2.
the autocomplete selection should be shown.
Actual behaviour
Autocomplete not working for library cv2
Steps to reproduce
- Install Python-OpenCV
sudo pacman -Syu python-opencv
- Make sure the files are in right path
pacman -Ql python-opencv
# output
python-opencv /usr/
python-opencv /usr/lib/
python-opencv /usr/lib/python3.9/
python-opencv /usr/lib/python3.9/site-packages/
python-opencv /usr/lib/python3.9/site-packages/cv2.cpython-39-x86_64-linux-gnu.so
python-opencv /usr/share/
python-opencv /usr/share/licenses/
python-opencv /usr/share/licenses/python-opencv/
python-opencv /usr/share/licenses/python-opencv/LICENSE
- Open VSCode and start writing code
Logs
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Thanks for the report. Could you please add the information in the report as described in the troubleshooting guide?
Enable trace logging: I'm not sure if I understood correctly, because I use Google translator.
[Info - 22:30:21] Pylance language server 2021.11.0 (pyright fb86eac6) starting
[Info - 22:30:21] Server root directory: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist
[Info - 22:30:21] No configuration file found.
[Info - 22:30:21] No pyproject.toml file found.
[Info - 22:30:21] Setting pythonPath for service "Video": "/bin/python"
[Warn - 22:30:21] stubPath /home/boris/Документы/Projects/OpenCV/Video/typings is not a valid directory.
[Info - 22:30:21] Assuming Python version 3.9
[Info - 22:30:21] Assuming Python platform Linux
Search paths for /home/boris/Документы/Projects/OpenCV/Video
/home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib
/home/boris/Документы/Projects/OpenCV/Video
/home/boris/Документы/Projects/OpenCV/Video/typings
/home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stubs/...
/home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/bundled/stubs
/usr/lib/python3.9
/usr/lib/python3.9/lib-dynload
/home/boris/.local/lib/python3.9/site-packages
/usr/lib/python3.9/site-packages
[Warn - 22:30:22] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn - 22:30:22] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn - 22:30:22] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn - 22:30:22] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Info - 22:30:22] Searching for source files
[Info - 22:30:22] Found 2 source files
[Info - 22:30:22] Background analysis(1) root directory: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist
[Info - 22:30:22] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: setImportResolver
Background analysis message: ensurePartialStubPackages
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: setFileOpened
[FG] parsing: /home/boris/Документы/Projects/OpenCV/Video/video_save.py (64ms)
[FG] parsing: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 12ms] (159ms)
[FG] binding: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/builtins.pyi (60ms)
[FG] binding: /home/boris/Документы/Projects/OpenCV/Video/video_save.py (2ms)
Background analysis message: analyze
[BG(1)] analyzing: /home/boris/Документы/Projects/OpenCV/Video/video_save.py ...
[BG(1)] parsing: /home/boris/Документы/Projects/OpenCV/Video/video_save.py (76ms)
[BG(1)] parsing: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 4ms] (166ms)
[BG(1)] binding: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/builtins.pyi (60ms)
[BG(1)] binding: /home/boris/Документы/Projects/OpenCV/Video/video_save.py (1ms)
[BG(1)] checking: /home/boris/Документы/Projects/OpenCV/Video/video_save.py ...
[BG(1)] parsing: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/typing.pyi [fs read 2ms] (59ms)
[BG(1)] binding: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/typing.pyi (26ms)
[BG(1)] parsing: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 1ms] (9ms)
[BG(1)] binding: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (2ms)
[BG(1)] parsing: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/typing_extensions.pyi [fs read 0ms] (5ms)
[BG(1)] binding: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/typing_extensions.pyi (3ms)
[BG(1)] parsing: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/abc.pyi [fs read 0ms] (1ms)
[BG(1)] binding: /home/boris/.vscode/extensions/ms-python.vscode-pylance-2021.11.0/dist/typeshed-fallback/stdlib/abc.pyi (0ms)
[BG(1)] parsing: /usr/lib/python3.9/site-packages/numpy/__init__.pyi [fs read 1ms] (206ms)
[BG(1)] binding: /usr/lib/python3.9/site-packages/numpy/__init__.pyi (63ms)
[BG(1)] checking: /home/boris/Документы/Projects/OpenCV/Video/video_save.py (439ms)
[BG(1)] analyzing: /home/boris/Документы/Projects/OpenCV/Video/video_save.py (744ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens full
[BG(1)] getSemanticTokens full at /home/boris/Документы/Projects/OpenCV/Video/video_save.py (8ms)
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 0:0 - 22:0 at /home/boris/Документы/Projects/OpenCV/Video/video_save.py (12ms)
Background analysis message: resumeAnalysis
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
State which language server version you are using: v2021.11.0 State the environment where your code is running: Python 3.9.7 A code example
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
while True:
ret, frame = cap.read()
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
cv2.imshow('frame', frame)
if cv2.waitKey(1) != -1:
break
cap.release()
cv2.destroyAllWindows()
Thanks, that's what we need. I don't see us finding cv2
, even though the .so
is in /usr/lib/python3.9/site-packages
. Potentially there's a bug in how we check for compiled modules and it's not recognizing cv2.cpython-39-x86_64-linux-gnu.so
.
Same thing here, macOS Mojave and Big Sur. Posted about it here
At first opencv
died in Big Sur. Import shows normal, but no autocomplete works, even after trying all the troubleshooting steps in issues and changing to python.analysis.extrapaths
. I even wiped VScode from my systsem completely and reinstalled from scratch. opencv worked for about 5 minutes and then stopped working again.
Same as @boris-gu , I even pointed to the .so
and lib
and site-packages
and nothing works.
Since the latest patch, now Mojave install of VScode exhibits same behavior.
I'm running numerous Anaconda envs (maybe 2-3 dozen) with different python versions and packages. I'm not sure if this is related, but many times since the last few patches, VScode displays the wrong env on the bottom left bar. Sometimes it will change if I repeatedly choose the correct one (and the correct one is usually selected when I go through the menu anyway). If I switch to another file using a different env, the display will often right itself. Odd thing, it's not even my default path. Might just be a display issue, but figured I'd mention it just in case.
The imutils are not seen in win10 vscode also.
Same with cv2
using conda on Windows.
It seems to be related to lib
files like .pyd
.
Here to confirm that opencv2 with conda on windows has the same behavior.
Hey just wanted to say that I had the same issue. I just bit the bullet and installed with pip and the expected behavior occurred.
I have the same issue on Archlinux. So, does this bug solved?
Hello, I reproduced this error with cv2 and I got the same issue here with an other *.so library (jsbsim). Any news ?
Strangely pylance has the stubs under
.vscode\extensions\ms-python.vscode-pylance\dist\bundled\stubs\cv2-stubs
My current workaround is to copy the __init__.pyi
file to the place where the package is installed.
For me, using conda under Lib\site-packages
creating a folder cv2
with the __init__.pyi
file.
Strangely pylance has the stubs under
.vscode\extensions\ms-python.vscode-pylance\dist\bundled\stubs\cv2-stubs
My current workaround is to copy the
__init__.pyi
file to the place where the package is installed. For me, using conda underLib\site-packages
creating a foldercv2
with the__init__.pyi
file.
Does renaming
.vscode\extensions\ms-python.vscode-pylance\dist\bundled\stubs\cv2-stubs
to
.vscode\extensions\ms-python.vscode-pylance\dist\bundled\stubs\cv2
fix it?
for the case its not working is always under linux? are you trying to build opencv locally? or pip installed the latest version?
I don't really use opencv nowadays, I was just searching for a similar issue to my similar problem with jsbsim module. I couldn't find a jsbsim directory in the .vscode\extensions\ms-python.vscode-pylance\dist\bundled\stubs\
so... I'm switching to Pycharm for now :/
This seems to work on a fresh pip install (WSL):
For conda, there doesn't seem to be an opencv-python install. You have to install it through pip. Then it works.
This is with a conda environment on Windows: