Skip to content
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

Import "gi.repository.GLib" could not be resolved from source #189

Open
laoshaw opened this issue Aug 4, 2024 · 9 comments
Open

Import "gi.repository.GLib" could not be resolved from source #189

laoshaw opened this issue Aug 4, 2024 · 9 comments

Comments

@laoshaw
Copy link

laoshaw commented Aug 4, 2024

After I did: pip install pygobject-stubs --no-cache-dir --config-settings=config=Gtk4,Gdk4,Soup3 (for gtk4), or just the default install(pip install pygobject-stubs pygobject), my vim still reports above warning, it runs, but the warning stays no matter what.

@theCapypara
Copy link
Contributor

Is your vim using a LSP or something that is actually aware of typestubs? If it's analyzing "real" code only it won't find it.

@laoshaw
Copy link
Author

laoshaw commented Aug 4, 2024

yes I'm using coc-nvim that has coc-pyright installed, it worked fine with other python packages, it can also autocomplete GLib and Gtk methods etc, but the warning (see the screenshot) always stays no matter what I try, not a showstopper though.

Screenshot from 2024-08-04 16-36-03

@Vazgen005
Copy link

I'm having the same problem. I'm using the Pylance extension from VsCode, which uses pyright under the hood.
image

@theCapypara
Copy link
Contributor

theCapypara commented Sep 19, 2024

The typestubs are normal PEP 561 typestubs.

If your editor or type checker does not find them then they are most likely not installed or something is not configured correctly on your end. Did you make sure to read the README and specifiy the config-settings to tell what stubs to generate?

You can try uninstalling the typestubs and reinstalling them, with the config-settings. Make sure to pass --no-cache-dir like explained in the README.
But if you do not specify config-settings, there are still default versions used. So it should still work. Still, confirm that the typestubs are actually installed.

After this, check if the typestubs are recognized by pyright itself (without VS Code).

@Vazgen005
Copy link

As @lashawn said, the stubs work fine. The only problem is the warning. That's all.
Perhaps the problem is on the pyright side.

@theCapypara
Copy link
Contributor

But if the imports are not resolved then how can the stubs work? Are you sure the warning isn't coming from VSCode itself?

@lovetox
Copy link
Collaborator

lovetox commented Sep 20, 2024

are you maybe using virtual environments? or conda environments? if yes you need to install the stubs in these environments.

if your stubs work otherwise, maybe open a issue on the pylance or pyright tracker and ask what the problem could be.

other things to check that come to mind

  • You should not have any other stubs for gi installed
  • You should not have gi or the stubs installed with the -e (editable) switch

Side Note:
gi.require_version() must come before the import, as it makes sure that version 4.0 is imported. Afterwards it does nothing.

@Vazgen005
Copy link

Vazgen005 commented Sep 21, 2024

Yes, i use venv.
Here's my setup:
image
I use rye for project management.

@Vazgen005
Copy link

Vazgen005 commented Oct 13, 2024

I solved this issue by adding following rule to pyproject.toml, corresponding to pyright documentation.

[tool.pyright]
reportMissingModuleSource = false

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

4 participants