Skip to content

Can not find compiled (pyd) module #8033

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

Closed
Djedouas opened this issue Nov 29, 2019 · 5 comments
Closed

Can not find compiled (pyd) module #8033

Djedouas opened this issue Nov 29, 2019 · 5 comments

Comments

@Djedouas
Copy link
Contributor

Hello,

I have the following directory structure:

|--my_libs/
      |--qgis/
      |--core/
      |     |--__init__.py
      |--_core.pyd

My mypy_path is set with a config file to the my_libs directory.

In the qgis.__init__ module there is a from qgis._core import * statement.

In my python test code I have:

from qgis._core import QgsAction
from qgis.core import QgsAction

The mypy output is:

error: Cannot find module named 'qgis._core'
error: Module 'qgis.core' has no attribute 'QgsAction'

On the first line mypy can't find the module, but on the second line the module is found, it's the attribute which is not found.

Because mypy can't find the _core module, it can't find the QgsAction attribute in the core module because the latter imports _core.

If mypy was able to find qgis._core there would be no error.

I don't understand why mypy can find qgis module whereas _core is not found, since they are in the same source folder.

Thanks !

@ilevkivskyi
Copy link
Member

Mypy doesn't support any binary/compiled Python formats (.pyc, .pyd, .so, etc), since it is a static type checker. Mypy needs to see source code .py, or a type stub .pyi (it's like a header file for Python). You can try using stubgen to generate .pyi for compiled files, see https://mypy.readthedocs.io/en/latest/stubgen.html

@Djedouas
Copy link
Contributor Author

OK!

I tried stubgen but it outputs an error:

Critical error during semantic analysis: mypy: can't decode file '_core.pyd': 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byte

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 29, 2019

The stubgen error is not releated pyd files -- can you create a new issue?

@kerim371
Copy link

I'm sorry for disturbing but I can't understand whether stubgen supports .pyd files or not? The question arised after I saw these links:

  1. Trying to generate .pyi from .pyd raises UnicodeDecodeError #5283
  2. creating stub pyi files automatically from pybind projects pybind/pybind11#2350 (comment)
    3but when I try to run the command stubgen mymodule.pyd I get error:
    Critical error during semantic analysis: mypy: stubgen does not support .pyd files

@Tinyblack
Copy link

I'm sorry for disturbing but I can't understand whether stubgen supports .pyd files or not? The question arised after I saw these links:

  1. Trying to generate .pyi from .pyd raises UnicodeDecodeError #5283
  2. creating stub pyi files automatically from pybind projects pybind/pybind11#2350 (comment)
    3but when I try to run the command stubgen mymodule.pyd I get error:
    Critical error during semantic analysis: mypy: stubgen does not support .pyd files

Sorry for disturbing. If you are still waiting for an answer to this problem, the short answer I think is yes. But you may need to alter the command a bit.
By referring to the comment #7692 (comment), the command I ran successfully is stubgen --parse-only -m mymodule (and try stubgen --parse-only --ignore-errors -m mymodule if some errors show). mymodule is the name of your module you used when generating your mymodule.pyd.
I hope this will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants