You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mypy cannot find library stubs for protobuf #10986
I'm having issues with mypy correctly finding type stubs.
After creating a virtual environment on my Fedora machine using virtualenv, I install the following packages:
pip install mypy protobuf types-protobuf
Using mypy to check the following code
importgoogle.protobuf
I get the error messsage:
my_file.py:1: error: Skipping analyzing "google": module is installed, but missing library stubs or py.typed marker [import-untyped]
my_file.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
The reason for this seems that in the virtual environment there are two independent lib directories (my_env/lib and my_env/lib64). One google directory containing code of the protobuf package is in lib64/google and the types (types-protobuf) are installed to lib/google-stubs.
Either moving the google-stubs directory to the lib64 variant or creating an (empty) google directory in lib resolves the issue.
It seems mypy is unable to find the corresponding type stubs in the respectively other lib directory.
Has anybody an idea on how to approach this? I do not even know whether the respective installation locations of either the protobuf or the types-protobuf package are correct or whether this is an issue with mypy resolving types?!
+1 It seems like only google-stubs/protobuf/__init__.pyi exists, so when doing import google.protobuf, mypy makes sure that both import google and import google.protobuf resolve, which fails.
cc @Avasam might be as easy as adding google/__init__.pyi
google/__init__.py does not exist though
Adding google/__init__.pyi would make all untyped google namespaced packages seen as typed
And mypy is (should be) able to resolve typed namespaced packages correctly (it's a core part of the spec).
I also cannot replicate op's situation locally (pretty sure their issue is caused by the my_env/lib vs my_env/lib64 differentiation, but I have no idea how to help or investigate that part)
I can reproduce the issue locally, but I don't see anything wrong with the installed types-protobuf package. It's a bit curious that this is the first time this comes up (the original issue seems to be related to some environment related weirdness) and we've just recently revamped the way packages are built. But I see no significant change between older types-protobuf packages and the newer one and I could reproduce the issue with types-protobuf==5.29.1.20250208 as well. I tend to assume that this is a mypy bug, possibly related to python/mypy#14057.
Anyway, I'm closing this issue, because the original issue seems to be unrelated to the problem by @brandonchinn178 and looks to be a weird problem related to the environment of the submitter.
@brandonchinn178: Could you open an issue against mypy, with your problem description?
Activity
brandonchinn178 commentedon Apr 4, 2025
+1 It seems like only
google-stubs/protobuf/__init__.pyiexists, so when doingimport google.protobuf, mypy makes sure that bothimport googleandimport google.protobufresolve, which fails.cc @Avasam might be as easy as adding
google/__init__.pyiAvasam commentedon Apr 4, 2025
@brandonchinn178
google/__init__.pydoes not exist thoughAdding
google/__init__.pyiwould make all untyped google namespaced packages seen as typedAnd mypy is (should be) able to resolve typed namespaced packages correctly (it's a core part of the spec).
I also cannot replicate op's situation locally (pretty sure their issue is caused by the
my_env/libvsmy_env/lib64differentiation, but I have no idea how to help or investigate that part)brandonchinn178 commentedon Apr 4, 2025
hm I'm not sure about OP's situation, but I'm encountering this issue:
python3 -m venv venvvenv/bin/pip install mypy types-protobufecho 'import google.protobuf.descriptor' > test.pyvenv/bin/mypy test.pyThis shows an error at "Could not find library
google". Can you repro that? What would be the recommended workaround?srittau commentedon Apr 4, 2025
I can reproduce the issue locally, but I don't see anything wrong with the installed
types-protobufpackage. It's a bit curious that this is the first time this comes up (the original issue seems to be related to some environment related weirdness) and we've just recently revamped the way packages are built. But I see no significant change between older types-protobuf packages and the newer one and I could reproduce the issue withtypes-protobuf==5.29.1.20250208as well. I tend to assume that this is a mypy bug, possibly related to python/mypy#14057.srittau commentedon Apr 4, 2025
Anyway, I'm closing this issue, because the original issue seems to be unrelated to the problem by @brandonchinn178 and looks to be a weird problem related to the environment of the submitter.
@brandonchinn178: Could you open an issue against mypy, with your problem description?