Open
Description
Hey team,
I wasn't sure if you would be comfortable with this, but what's your opinion on telling the user when they are missing a pydantic dependency, such as pydantic-settings
is using BaseSettings
in Pydantic V1?
This could spit out a warning (whether that's stdout, stderr, log.txt, or somewhere else) or a # TODO
comment if the pydantic-settings
package isn't installed.
This will help users more quickly identify when their application requires packages that are not currently installed.
To detect if a package is installed without importing it (for safety reasons), importlib.util
can be used:
from importlib.util import find_spec
print(find_spec("pydantic-settings"))
# ''
print(find_spec("pydantic"))
# 'ModuleSpec(name='pydantic', loader=<_frozen_importlib_external.SourceFileLoader object at 0x104e18240>, origin='/Users/kkirsche/.asdf/installs/python/3.11.4/lib/python3.11/site-packages/pydantic/__init__.py', submodule_search_locations=['/Users/kkirsche/.asdf/installs/python/3.11.4/lib/python3.11/site-packages/pydantic'])'
Documentation on find_spec
:
https://docs.python.org/3/library/importlib.html#importlib.util.find_spec