IDE doesn't find module in import (using "uv")

Hello.

I'm using PyCharm Pro 2025.3.3.

I would like to develop an OAuth2 client using the authlib package. Even the first import

 from authlib.integrations.requests_client import OAuth2Session

fails already with errors of Cannot find reference 'requests_client' in 'authlib.integrations' and Unresolved reference 'OAuth2Session'.

The weird thing is that the package and all dependencies are visible on the "Python Packages" tab. Also, I can successfully run the import in the "Python Console" tab for my project.

I'm using an uv environment, in case it matters. I created it with PyCharm.

I have no clue what's wrong (I admit that I'm not very experienced with PyCharm, nor with coding in Python). Anybody got any idea?

Thanks in advance.

Kind regards,

Ralf

0

Hi Ralf Bergs, just to clarify: are you only seeing “Unresolved references” in the editor, or does the issue also affect actually running the script?

Could you please share a few screenshots showing the behavior?

Also, have you tried running the script from a system terminal outside the IDE using the same virtual environment? If it fails there with the same error, then the problem is most likely not related to PyCharm.

Have you also tried invalidating caches via File | Invalidate Caches | Invalidate and Restart? If so, did it make any difference?

 

0

Thank you for your comments.

I'm at the very beginning of development, so there is nothing to run yet. Here's a screenshot of what I'm seeing in PyCharm:

As I said, running the import from the PyCharm “Python Console” works ok, so I'm pretty sure the “uv” environment sees all packages and dependencies it requires.

I didn't see any point in trying to progress with my script, as the very basics seem to be failing already.

I have indeed already invalidated the cache and restarted the IDE – to no avail. :-(

Anything else I could try?

Kind regards,

Ralf

0

Ralf Bergs, thank you for the screenshot, that’s very helpful.

It looks like type stubs for authlib may be missing. Could you try installing them with the following command and see if it helps?

uv add types-authlib
1

Yesssss!!!! That helped… Thanks a million…

Just for my understanding: Is that a “bug” with regards to the package dependencies, i.e. a bug in the “authlib” package? Or is it a bug in PyCharm? (unlikely I guess)

0

Ralf Bergs, This is expected behavior rather than a bug. The authlib package does not provide complete type hints, so PyCharm cannot resolve some imports statically. Installing the types-authlib package adds the missing type information, which is why the warnings disappear. The runtime itself is unaffected, as you’ve already observed in the Python console.

1

Thanks very much, I understand.

It gets off-topic now, but maybe you're still willing to help (if not that's ok!): How does one know about this? Let's say I need to include another external package for some functionality I don't want to “reinvent.” How would I know that the type hinting is not available before I install another package? Just by looking for symptoms in PyCharm as the ones I was seeing? Or is there some “systematic” way to find out? Is the name of the package to include always types-foobar for a package called foobar?

Many thanks again for your help.

0

Is the name of the package to include always types-foobar for a package called foobar?

Not always. A lot of third-party stubs published from typeshed use the types-<library> naming on PyPI, but the typing docs also call out <library>-stubs as a common pattern.

In your specific case, types-Authlib exists on PyPI as a stub package for Authlib, which is why installing it fixed the editor warnings without changing runtime behavior. Type stubs are only for static analysis; they do not affect Python execution itself.

A rule of thumb is this: if the import works at runtime but PyCharm (or pyright/mypy, etc.) complains in the editor, the first things to suspect are missing or incomplete typing support, not a broken package.

 

1

Great and very helpful info, thank you so much.

0

@ Mikhail  I like how you broke it down with a simple rule of thumb, that makes it way easier to understand what’s going on when those editor warnings pop up.

Also, pointing out the difference between runtime behavior and static typing is super useful, especially for people who are new to type stubs. Solid answer!

0

请先登录再写评论。