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

Multiple libraries not recognized with errors is not a known attribute of module #5892

Open
ClaudioCimarelli opened this issue May 17, 2024 · 6 comments
Assignees
Labels
external bug needs repro Issue has not been reproduced yet user responded Was "waiting for user response" and they responded waiting for upstream Waiting for upstream to release a fix

Comments

@ClaudioCimarelli
Copy link

Environment data

  • Language Server version: v2024.5.1
  • OS and version: Windows 11 with WSL2
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.11.7 within conda 23.5.0 env

Code Snippet

I am experiencing the following issue when importing libraries that are correctly installed in the current environment in the Python console, I have the auto-completion working, and using the functions works, too.

image
image

image
image

To quickly solve this, I am using the # type: ignore comment next to each import or line, but of course, I would like to have this working as the object types are not recognized, and it's not ideal.

Lastly, I also noticed that the import warnings do not change if I switch environments.

Logs

Pylance output

2024-05-17 09:36:01.693 [info] (Client) Pylance async client (2024.5.1) started with python extension (2024.4.1)
2024-05-17 09:36:02.295 [info] [Info  - 9:36:02 AM] (45452) Pylance language server 2024.5.1 (pyright version 1.1.360, commit 4bc8428d) starting
2024-05-17 09:36:02.303 [info] [Info  - 9:36:02 AM] (45452) Server root directory: file:///home/claudio/.vscode-server/extensions/ms-python.vscode-pylance-2024.5.1/dist
2024-05-17 09:36:02.370 [info] [Info  - 9:36:02 AM] (45452) Starting service instance "EVbatteryDetection"
2024-05-17 09:36:02.374 [info] [Info  - 9:36:02 AM] (45452) Auto-Indent enabled
2024-05-17 09:36:03.114 [info] [Info  - 9:36:03 AM] (45452) Setting pythonPath for service "EVbatteryDetection": "/bin/python"
2024-05-17 09:36:03.129 [info] [Info  - 9:36:03 AM] (45452) Setting environmentName for service "EVbatteryDetection": "3.10.12 (global)"
2024-05-17 09:36:03.138 [info] [Info  - 9:36:03 AM] (45452) Assuming Python version 3.10.12.final.0
2024-05-17 09:36:03.954 [info] [Info  - 9:36:03 AM] (45452) Found 21 source files
2024-05-17 09:36:04.272 [info] [Info  - 9:36:04 AM] (45452) Background analysis(1) root directory: file:///home/claudio/.vscode-server/extensions/ms-python.vscode-pylance-2024.5.1/dist
2024-05-17 09:36:04.272 [info] [Info  - 9:36:04 AM] (45452) Background analysis(1) started
2024-05-17 09:36:04.587 [info] [Info  - 9:36:04 AM] (45452) Indexer background runner(2) root directory: file:///home/claudio/.vscode-server/extensions/ms-python.vscode-pylance-2024.5.1/dist (index)
2024-05-17 09:36:04.587 [info] [Info  - 9:36:04 AM] (45452) Indexing(2) started
2024-05-17 09:36:05.933 [info] [Info  - 9:36:05 AM] (45452) scanned(2) 488 files over 1 exec env
2024-05-17 09:36:06.559 [info] [Info  - 9:36:06 AM] (45452) indexed(2) 317 files over 1 exec env
2024-05-17 09:36:06.901 [info] [Info  - 9:36:06 AM] (45452) Indexing finished(2).
2024-05-17 09:36:50.337 [info] [Info  - 9:36:50 AM] (45452) Setting pythonPath for service "EVbatteryDetection": "/home/claudio/miniconda3/envs/ev_env/bin/python"
2024-05-17 09:36:50.338 [info] [Info  - 9:36:50 AM] (45452) Setting environmentName for service "EVbatteryDetection": "3.11.7 (ev_env conda)"
2024-05-17 09:36:50.384 [info] [Info  - 9:36:50 AM] (45452) Assuming Python version 3.11.7.final.0
2024-05-17 09:36:51.567 [info] [Info  - 9:36:51 AM] (45452) Found 21 source files
2024-05-17 09:36:52.258 [info] [Info  - 9:36:52 AM] (45452) Indexer background runner(3) root directory: file:///home/claudio/.vscode-server/extensions/ms-python.vscode-pylance-2024.5.1/dist (index)
2024-05-17 09:36:52.258 [info] [Info  - 9:36:52 AM] (45452) Indexing(3) started
2024-05-17 09:36:53.349 [info] [Info  - 9:36:53 AM] (45452) scanned(3) 369 files over 1 exec env
2024-05-17 09:36:54.004 [info] [Info  - 9:36:54 AM] (45452) indexed(3) 276 files over 1 exec env
2024-05-17 09:36:54.186 [info] [Info  - 9:36:54 AM] (45452) Indexing finished(3).```
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label May 17, 2024
@heejaechang
Copy link
Contributor

can you provide us a log using (https://github.com/microsoft/pylance-release/wiki/Collecting-data-for-an-investigation.#collecting-trace-logs-using-commands) ?

...

for cv2.SIFT_create issue, looks like cv2 (which is a native module)'s __init__.pyi doesn't have that method in it. the cv2 package maintainer need to add that to their __init__.pyi

@debonte debonte added the waiting for user response Requires more information from user label May 19, 2024
@ClaudioCimarelli
Copy link
Author

Hi, thanks for your answer. This is the log in which there are import errors relative to the Open3D library:
pylance_2024.5.1_id_0.txt

For OpenCV, how is it that in the Python console, I can autocomplete these methods, and in VSCode, I cannot? These functions were recognized in a previous version of Opencv.

@github-actions github-actions bot added user responded Was "waiting for user response" and they responded and removed waiting for user response Requires more information from user labels May 22, 2024
@heejaechang
Copy link
Contributor

how is it that in the Python console

I am not sure what you meant by Python console. that said, if it is actually running python code then they could inspect that object in memory to get all dynamically generated symbols, but we are static analysis tool which won't run any python code. instead we analyze source file (*.py and *.pyi) to retrieve that information. so if source doesn't have it, then we don't know that exists.

These functions were recognized in a previous version of Opencv.

you meant previous version of pylance? can you tell us which version that was? then we can take a look to see how.

@heejaechang
Copy link
Contributor

heejaechang commented May 22, 2024

I looked through history a bit. looks like opencv used to didn't provide *.pyi files so it was using ours (https://github.com/bschnurr/pyrx/blob/4791634be3161aa6ee3b4d84cc45b4a4ff4b0a1c/packages/pylance-internal/bundled/stubs/cv2-stubs/__init__.pyi) but the latest version of opencv now provides its own *.pyi, so we no longer bundle our owns (since one from package maintainers should be better than ours). that's probably why.

I think you should open an issue on openCV repro asking them to add SIFT_create.

that said, ours looked like this

def SIFT_create(nfeatures=..., nOctaveLayers=..., contrastThreshold=..., edgeThreshold=..., sigma=...) -> typing.Any:

so, probably it wasn't that helpful either anyway .

@ClaudioCimarelli
Copy link
Author

Thanks for your reply.

By Python console, I just meant running python interactively.

I found the info you told me about also here. If OpenCV now provides its own .pyi (the link you gave is not found), why are they not working if I have the latest pip package?

For Open3D should I open an issue with them? Is this #138 (comment) a viable solution in this cases?

@heejaechang
Copy link
Contributor

heejaechang commented May 22, 2024

the link you gave is not found

ah, sorry, linked wrong path. here is right one.
https://github.com/microsoft/python-type-stubs/blob/1add73961cc8251a8b2dad5e46ee8d78a9f260f8/stubs/cv2-stubs/__init__.pyi#L1371

For Open3D should I open an issue with them

ya, you should open an issue with them. they need to add it to their __init__.pyi

Is this #138 (comment) a viable solution in this cases?

there will be many ways to work around this issue until maintainer fixes the issue. but I think the easiest way for you for now is probably you just updating __init__.pyi installed by cv2 package to contain sift_create

*.pyi file will only affect your editing experience but not runtime experience.

issue go to declaration command on cv2 in import cv2. when __init__.pyi is opened in the editor, add this line to the end of the file.

def SIFT_create(nfeatures=..., nOctaveLayers=..., contrastThreshold=..., edgeThreshold=..., sigma=...) -> SIFT:
    '@param nfeatures The number of best features to retain. The features are ranked by their scores\n.       (measured in SIFT algorithm as the local contrast)\n.   \n.       @param nOctaveLayers The number of layers in each octave. 3 is the value used in D. Lowe paper. The\n.       number of octaves is computed automatically from the image resolution.\n.   \n.       @param contrastThreshold The contrast threshold used to filter out weak features in semi-uniform\n.       (low-contrast) regions. The larger the threshold, the less features are produced by the detector.\n.   \n.       @note The contrast threshold will be divided by nOctaveLayers when the filtering is applied. When\n.       nOctaveLayers is set to default and if you want to use the value used in D. Lowe paper, 0.03, set\n.       this argument to 0.09.\n.   \n.       @param edgeThreshold The threshold used to filter out edge-like features. Note that the its meaning\n.       is different from the contrastThreshold, i.e. the larger the edgeThreshold, the less features are\n.       filtered out (more features are retained).\n.   \n.       @param sigma The sigma of the Gaussian applied to the input image at the octave \\#0. If your image\n.       is captured with a weak camera with soft lenses, you might want to reduce the number.'
    ...

that should make it work until it is fixed by the maintainer in new version of cv2.

@heejaechang heejaechang added waiting for upstream Waiting for upstream to release a fix external bug labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external bug needs repro Issue has not been reproduced yet user responded Was "waiting for user response" and they responded waiting for upstream Waiting for upstream to release a fix
Projects
None yet
Development

No branches or pull requests

4 participants