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

Opencv intellisence fails #912

Closed
jahaniam opened this issue Feb 4, 2021 · 14 comments
Closed

Opencv intellisence fails #912

jahaniam opened this issue Feb 4, 2021 · 14 comments
Labels
bug Something isn't working needs investigation Could be an issue - needs investigation

Comments

@jahaniam
Copy link

jahaniam commented Feb 4, 2021

I am writing a dockerfile and I have RUN pip install opencv-python

Pip will install the opencv as sudo in the /usr/local/lib/python3.6/site-packages/cv2
I cannot get the autocomplete feature.

test

Here is my tracing output:

[Info  - 12:02:54 AM] Pylance language server 2021.1.3 (pyright 61c53da4) starting
[Info  - 12:02:54 AM] Server root directory: /home/vscode/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.1.3/dist
[Info  - 12:02:54 AM] No configuration file found.
[Info  - 12:02:54 AM] Setting pythonPath for service "vscode": "/usr/bin/python3"
Search paths found for configured python interpreter:
  /usr/lib/python3.6
  /usr/lib/python3.6/lib-dynload
  /home/vscode/.local/lib/python3.6/site-packages
  /usr/local/lib/python3.6/dist-packages
  /usr/lib/python3/dist-packages
[Error - 12:02:54 AM] stubPath /home/vscode/typings is not a valid directory.
[Info  - 12:02:54 AM] Assuming Python version 3.6
[Info  - 12:02:54 AM] Assuming Python platform Linux
[Info  - 12:02:54 AM] Searching for source files
[Info  - 12:02:54 AM] Found 4249 source files
[Info  - 12:02:54 AM] Background analysis(1) root directory: /home/vscode/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.1.3/dist
[Info  - 12:02:54 AM] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: setFileOpened
Background analysis message: getSemanticTokens
[BG(1)] parsing: /home/vscode/x.py (15ms)
[BG(1)] parsing: /home/vscode/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.1.3/dist/typeshed-fallback/stdlib/3/builtins.pyi [fs read 2ms] (128ms)
[BG(1)] binding: /home/vscode/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.1.3/dist/typeshed-fallback/stdlib/3/builtins.pyi (48ms)
[BG(1)] binding: /home/vscode/x.py (0ms)
[BG(1)] parsing: /usr/local/lib/python3.6/dist-packages/cv2/__init__.py [fs read 0ms] (8ms)
[BG(1)] binding: /usr/local/lib/python3.6/dist-packages/cv2/__init__.py ...
[BG(1)]   parsing: /usr/local/lib/python3.6/dist-packages/cv2/data/__init__.py [fs read 0ms] (0ms)
[BG(1)]   binding: /usr/local/lib/python3.6/dist-packages/cv2/data/__init__.py (0ms)
[BG(1)] binding: /usr/local/lib/python3.6/dist-packages/cv2/__init__.py (3ms)
[BG(1)] parsing: /home/vscode/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.1.3/dist/typeshed-fallback/stdlib/2and3/_typeshed/__init__.pyi [fs read 1ms] (13ms)
[BG(1)] binding: /home/vscode/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.1.3/dist/typeshed-fallback/stdlib/2and3/_typeshed/__init__.pyi (2ms)
[BG(1)] parsing: /home/vscode/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.1.3/dist/typeshed-fallback/third_party/2and3/typing_extensions.pyi [fs read 0ms] (6ms)
[BG(1)] binding: /home/vscode/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.1.3/dist/typeshed-fallback/third_party/2and3/typing_extensions.pyi (2ms)
[BG(1)] parsing: /home/vscode/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.1.3/dist/typeshed-fallback/stdlib/3/typing.pyi [fs read 2ms] (38ms)
[BG(1)] binding: /home/vscode/.vscode-server-insiders/extensions/ms-python.vscode-pylance-2021.1.3/dist/typeshed-fallback/stdlib/3/typing.pyi (12ms)
Background analysis message: getSemanticTokens
Background analysis message: analyze
[BG(1)] analyzing: /home/vscode/x.py ...
[BG(1)]   checking: /home/vscode/x.py (2ms)
[BG(1)] analyzing: /home/vscode/x.py (2ms)
Background analysis message: resumeAnalysis

Solution:

Opencv IntelliSense fails if it is installed in /usr/local/lib/pythonX/site-packages. I have to install it using pip install --user which is not common in many Dockerfiles.
It works fine if it is installed under $HOME/.local/lib/pythonX/site-packages

How to reproduce the issue:

  1. make sure to deactivate conda and other environments.
  2. sudo pip3 install opencv-python
  3. make sure it is installed under /usr/local/lib/pythonX/site-packages : python -c "import cv2;print(cv2.__file__)"
  4. open vscode and see IntelliSense fails

fix:

sudo pip uninstall opencv-python
pip install opencv-python --user

PS. I know we should never use sudo pip but sometimes this is unavoidable especially in containers and other provided images. There is something wrong with opencv package being in this directory for intellisense.

Related issue:
#138

@github-actions github-actions bot added the triage label Feb 4, 2021
@savannahostrowski savannahostrowski added bug Something isn't working compiled fixed in next version (main) A fix has been implemented and will appear in an upcoming version needs investigation Could be an issue - needs investigation and removed triage fixed in next version (main) A fix has been implemented and will appear in an upcoming version labels Feb 4, 2021
@chitalian
Copy link

chitalian commented Feb 5, 2021

I am running into the same issue. However

sudo pip uninstall opencv-python
pip install opencv-python --user

Doesn't solve my issue.

I don't know how to get tracing info. If someone can show me, I can share

@jahaniam
Copy link
Author

jahaniam commented Feb 5, 2021

Check where your opencv is installed.
for tracing see the related issue. Someone from pylance team shared a link

@jakebailey
Copy link
Member

@chitalian
Copy link

I am on macOS. I see a folder called cv2 here
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
I also see a folder call cv2 here
/Users/<user>/Library/Python/3.8/lib/python/site-packages

@jakebailey
Copy link
Member

I'm most interested in trace logs if you can provide them, thanks.

@chitalian
Copy link

I am thinking my sys.path is a bit messed up. anyway here is the log
log.txt

@jakebailey
Copy link
Member

That's the "Python" output window; I'm looking for the "Python Language Server" output window when you have logLevel set to Trace.

This is mainly to look for log lines that show that we aren't loading our bundled native stubs.

@chitalian
Copy link

chitalian commented Feb 5, 2021

I am getting it from here? It says Python Language Server on the top right - is this the right place?

image

@jakebailey
Copy link
Member

My mistake, thanks.

@jahaniam
Copy link
Author

jahaniam commented Feb 5, 2021

what is your output for this?

import cv2
print(cv2.__file__)

Something is wrong with your python

@jakebailey
Copy link
Member

Yes, we're failing to even run python to get the normal info we need (sys.path, the python version, etc). That protobuf pth file appears to be causing issues. If we can't call python, we probably won't be able to resolve much of anything. I don't know if your issue is related to the OP.

@chitalian
Copy link

thanks all - I figured it out. I had a python2 package in my PYTHONPATH. And when I was testing I only reloaded the window. But you have to close the entire process to reset env for vscode.

@bschnurr
Copy link
Member

closing this issue since I was related to opencv being installed in a different location than the interpreter.

@bschnurr
Copy link
Member

The next release of Pylance will have a partial stub for opencv, and this should help fix issues where we couldn't match the native stub to the installed user version of opencv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs investigation Could be an issue - needs investigation
Projects
None yet
Development

No branches or pull requests

5 participants