pyright icon indicating copy to clipboard operation
pyright copied to clipboard

Pyright can't resolve imported pyd module

Open spindensity opened this issue 7 years ago • 6 comments

Pyright can't resolve imported pyd module, it's nothing to do with any python venv path related configurations.

Please see https://github.com/microsoft/pyright/issues/209#issuecomment-522655817.

spindensity avatar Aug 19 '19 16:08 spindensity

I've added support for resolving ".pyd" files (third-party files only, not local) in pyright's import resolution logic. This will be in the next release.

erictraut avatar Aug 22 '19 22:08 erictraut

This is implemented in 1.0.57, which I just published.

erictraut avatar Aug 23 '19 13:08 erictraut

I still get Import 'cv2' could not be resolved pyright with pyright version 1.0.59

karipulli avatar Sep 08 '19 16:09 karipulli

I'll need more details about your specific case.

Are you using the VS Code extension? If so, please open the "Output" tab for Pyright and see if you can find the related verbose output relating to the import resolution for this file. Pyright logs all import failures.

If you're using the command-line extension, please run it with the "--verbose" flag and do the same.

erictraut avatar Sep 08 '19 16:09 erictraut

I'm using VS Code extension, on Mac.

my cv2 is in

extension module 'cv2' loaded from

'/anaconda3/envs/py36/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so'

The Pyright output is ould not import 'cv2' in file '/Users/karipulli/src/rax/wafertools/SEM_images/SEM_image_analysis.py' Looking for typeshed stdlib path Attempting to resolve using root path '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.7' Could not find directory '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.7/cv2' Did not find file '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.7/cv2.pyi' or '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.7/cv2.py' Attempting to resolve using root path '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.6' Could not find directory '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.6/cv2' Did not find file '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.6/cv2.pyi' or '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.6/cv2.py' Attempting to resolve using root path '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.5' Could not find directory '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.5/cv2' Did not find file '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.5/cv2.pyi' or '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3.5/cv2.py' Attempting to resolve using root path '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3' Could not find directory '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3/cv2' Did not find file '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3/cv2.pyi' or '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/3/cv2.py' Attempting to resolve using root path '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/2and3' Could not find directory '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/2and3/cv2' Did not find file '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/2and3/cv2.pyi' or '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/stdlib/2and3/cv2.py' Typeshed path not found Looking in root directory of execution environment '/Users/karipulli/src/rax/wafertools/SEM_images' Attempting to resolve using root path '/Users/karipulli/src/rax/wafertools/SEM_images' Could not find directory '/Users/karipulli/src/rax/wafertools/SEM_images/cv2' Did not find file '/Users/karipulli/src/rax/wafertools/SEM_images/cv2.pyi' or '/Users/karipulli/src/rax/wafertools/SEM_images/cv2.py' Looking for typeshed path Looking for typeshed third_party path Attempting to resolve using root path '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/third_party/2and3' Could not find directory '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/third_party/2and3/cv2' Did not find file '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/third_party/2and3/cv2.pyi' or '/Users/karipulli/.vscode/extensions/ms-pyright.pyright-1.0.59/typeshed-fallback/third_party/2and3/cv2.py' Typeshed path not found Looking in python search path '/anaconda3/envs/py36/lib/python3.6' Attempting to resolve using root path '/anaconda3/envs/py36/lib/python3.6' Could not find directory '/anaconda3/envs/py36/lib/python3.6/cv2' Did not find file '/anaconda3/envs/py36/lib/python3.6/cv2.pyi' or '/anaconda3/envs/py36/lib/python3.6/cv2.py' Looking in python search path '/anaconda3/envs/py36/lib/python3.6/lib-dynload' Attempting to resolve using root path '/anaconda3/envs/py36/lib/python3.6/lib-dynload' Could not find directory '/anaconda3/envs/py36/lib/python3.6/lib-dynload/cv2' Did not find file '/anaconda3/envs/py36/lib/python3.6/lib-dynload/cv2.pyi' or '/anaconda3/envs/py36/lib/python3.6/lib-dynload/cv2.py' Looking in python search path '/Users/karipulli/.local/lib/python3.6/site-packages' Attempting to resolve using root path '/Users/karipulli/.local/lib/python3.6/site-packages' Could not find directory '/Users/karipulli/.local/lib/python3.6/site-packages/cv2' Did not find file '/Users/karipulli/.local/lib/python3.6/site-packages/cv2.pyi' or '/Users/karipulli/.local/lib/python3.6/site-packages/cv2.py' Looking in python search path '/anaconda3/envs/py36/lib/python3.6/site-packages' Attempting to resolve using root path '/anaconda3/envs/py36/lib/python3.6/site-packages' Could not find directory '/anaconda3/envs/py36/lib/python3.6/site-packages/cv2' Did not find file '/anaconda3/envs/py36/lib/python3.6/site-packages/cv2.pyi' or '/anaconda3/envs/py36/lib/python3.6/site-packages/cv2.py' Looking in python search path '/Users/karipulli/src/rax/wafertools/rlib_src' Attempting to resolve using root path '/Users/karipulli/src/rax/wafertools/rlib_src' Could not find directory '/Users/karipulli/src/rax/wafertools/rlib_src/cv2' Did not find file '/Users/karipulli/src/rax/wafertools/rlib_src/cv2.pyi' or '/Users/karipulli/src/rax/wafertools/rlib_src/cv2.py'

Kari

On Sun, Sep 8, 2019 at 9:42 AM Eric Traut [email protected] wrote:

I'll need more details about your specific case.

Are you using the VS Code extension? If so, please open the "Output" tab for Pyright and see if you can find the related verbose output relating to the import resolution for this file. Pyright logs all import failures.

If you're using the command-line extension, please run it with the "--verbose" flag and do the same.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/microsoft/pyright/issues/211?email_source=notifications&email_token=AAUHBKNOACMR3WHE7TAHVELQIUTOZA5CNFSM4INDYRP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6FUA2Q#issuecomment-529219690, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUHBKKOO54KAQ4STVLIIHLQIUTOZANCNFSM4INDYRPQ .

karipulli avatar Sep 09 '19 02:09 karipulli

OK, so this has nothing to do with the original bug reported here because this isn't a ".pyd" import issue.

It looks like you're trying to import a module that has no ".py", just a ".so" (binary) file. Pyright doesn't support this. As a workaround, you should create a custom type stub file ("cv2.pyi") that defines that interface to your library.

erictraut avatar Sep 09 '19 03:09 erictraut