Pyright: Pyright can't resolve imported pyd module

Created on 4 Nov 2019  路  8Comments  路  Source: microsoft/pyright

See #211, maybe a regression.

  • OS: Win10 1903 64bit;
  • Python: Miniconda3 with python 3.7.5 environment;
  • Pyright: 1.0.82;
  • VS Code: 1.39.2.
bug question

All 8 comments

Hmm, nothing has changed in this code path for a while, so it's unlikely to be a regression.

Could you provide a few more details?

  1. Is the pyd module a third-party module (e.g. in one of the python search paths for your current python environment), or is it located within your workspace?
  2. If it's a third-party module, what package is it part of?
  3. What is the import statement that you're using to access it?
  1. The module is opencv, it's in the python search paths for the current python environment, and Microsoft python language server can resolve it flawlessly;
  2. Opencv;
  3. import cv2

See image:

Snipaste_2019-11-05_13-13-03

Ah, this sounds identical to #211, which was resolved "as designed". That import doesn't resolve to a pyd file. It's a raw ".so" library, which isn't supported by pyright. You can work around it by providing a local type stub file (cv2.pyi).

On windows it's not a raw ".so" library as the original https://github.com/microsoft/pyright/issues/209#issuecomment-522655817 reported, the ".so" library problem is not a part of issue #211:

Snipaste_2019-11-05_14-00-57

This should have been fixed in pyright 1.0.57 as your https://github.com/microsoft/pyright/issues/211#issuecomment-524319428 pointed out.

Ah, good point. I missed the point that you were running it on Windows. OK, I'll look into it further. Thanks for reporting the issue.

Sorry for taking so long on this. I've been busy with a bunch of other things. I had a chance to try this on a Windows machine. I installed opencv in my environment using "pip install opencv-python". It installed a top-level __init__.py in the cv2 site-libraries directory, and pyright was able to resolve this file correctly. I also see a "cv2.cp37-win_amd64.pyd" file in the same directory, but the __init__.py should take precedence.

Could you try with the latest version of pyright and confirm that you're still seeing the problem? If so, I'll need more details to help me repro the problem as you're seeing it.

Thanks for your reply.

After some investigation, I found the problem is caused by the specific package I use, perhaps there's no need to fix anything,

I use the opencv package from UCI, Here's the link: https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv. The installed directory structure is:

site-packages
    |--- cv.py
    |--- cv2.cp37-win_amd64.pyd

cv.py:

from cv2.cv import *

I can use import cv with no errors.

Sorry for the trouble.

OK, sounds like a good workaround.

Was this page helpful?
0 / 5 - 0 ratings