I’m trying to silence pkg_resources deprecation warnings but I don’t seem to be able to tame them:
# First attempt
❯ python -W ignore:pkg_resources -c "from kedro_datasets.pandas import CSVDataSet"
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
# Second attempt
❯ python -W ignore::DeprecationWarning -c "from kedro_datasets.pandas import CSVDataSet"
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
# Third attempt
>>> import warnings
>>> warnings.simplefilter("ignore", DeprecationWarning)
>>> from kedro_datasets.pandas import CSVDataSet
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
# Fourth and desperate attempt
>>> import warnings
>>> warnings.simplefilter("ignore")
>>> from kedro_datasets.pandas import CSVDataSet
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
Any pointers? I’m not sure why these warnings seem to behave differently.
Per the docs for warnings, this is telling Python that you want to treat DeprecationWarning as an error. I think what you actually want is to ignore it:
Thanks @jamestwebber , but either action doesn’t work. I’ll update the body of the post for consistency, but here’s what happens if I try to silence:
❯ python -W ignore:pkg_resources -c "from kedro_datasets.pandas import CSVDataSet" (kedro310-dev)
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
declare_namespace(pkg)
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google.cloud')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
declare_namespace(pkg)
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/pkg_resources/__init__.py:2349: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
declare_namespace(parent)
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google.logging')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
declare_namespace(pkg)
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
declare_namespace(pkg)
/Users/juan_cano/.micromamba/envs/kedro310-dev/lib/python3.10/site-packages/google/rpc/__init__.py:20: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google.rpc')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
pkg_resources.declare_namespace(__name__)
$ python -c "import pkg_resources; pkg_resources.declare_namespace('test')"
<string>:1: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('test')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
Suppressing this specific warning by suppressing them for the pkg_resources module doesn’t sem to work:
$ python -W 'ignore::DeprecationWarning:pkg_resources' -c "import pkg_resources; pkg_resources.declare_namespace('test')"
<string>:1: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('test')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
Guessing that’s because of the stacklevel=2. But we can match the start of the message:
Thanks @effigies , but we’re still not quite there.
It seems to be possible to silence warnings that come after calling pkg_resources directly. But if your code triggers a pkg_resources call somewhere else, not even -Wignore (ignore all warnings) will work.
Well, the problem was that there was a global warnings.simplefilter("default", DeprecationWarning) hidden in one of the modules I was importing, which was overriding everything I was doing. Case closed, for now. Sorry all for the noise!