Problem
In PyCharm editor displays unresolved references (red underlines) for exported functions in .so shared objects, even though the Python script using these functions runs correctly, and the functions work as expected.
Cause
PyCharm cannot infer the Python-level API from .so files through static analysis. It requires either binary skeletons or explicit .pyi stub files. When the .so file is directly in the project, PyCharm may not detect it for code insight purposes, causing it to flag the functions as unresolved.
Resolution
Option 1: Install the extension into the project interpreter
-
Navigate to the directory containing
setup.py. -
Run the following command using the interpreter configured in PyCharm:
python -m pip install . -
Rescan the interpreter packages or reopen the project.
This installs the module as a package, allowing PyCharm to generate or use the required skeletons.
Option 2: Add a stub file
-
Create a
.pyifile adjacent to the .so module. -
Declare the exported names in the
.pyifile. Example:def getrandom(n: int) -> int: ... __all__ = ["getrandom"]
Comments
0 comments
Please sign in to leave a comment.