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

DeprecationWarning: pkg_resources is deprecated as an API #16756

Open
adamjstewart opened this issue Feb 14, 2023 · 8 comments
Open

DeprecationWarning: pkg_resources is deprecated as an API #16756

adamjstewart opened this issue Feb 14, 2023 · 8 comments
Assignees
Labels
3rd party Related to a 3rd-party bug Something isn't working help wanted Open to be worked on priority: 1 Medium priority task
Milestone

Comments

@adamjstewart
Copy link
Contributor

adamjstewart commented Feb 14, 2023

Bug description

setuptools 67.3, released yesterday, officially deprecates pkg_resources.declare_namespace: https://setuptools.pypa.io/en/latest/history.html#v67-3-0

How to reproduce the bug

With setuptools 67.3+ installed:

$ python -Werror -c 'from pytorch_lightning import LightningDataModule'

Error messages and logs

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    from pytorch_lightning import LightningDataModule
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/pytorch_lightning/__init__.py:34: in <module>
    from lightning_fabric.utilities.seed import seed_everything  # noqa: E402
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/lightning_fabric/__init__.py:29: in <module>
    __import__("pkg_resources").declare_namespace(__name__)
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/pkg_resources/__init__.py:2297: in declare_namespace
    warnings.warn(msg, DeprecationWarning, stacklevel=2)
DeprecationWarning: 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

Environment

Current environment
#- Lightning Component: LightningModule
#- PyTorch Lightning Version: 1.9.1
#- Lightning App Version: N/A
#- PyTorch Version: 1.13.1
#- Python version: 3.8.16
#- OS: Ubuntu 22.04.1
#- CUDA/cuDNN version: N/A
#- GPU models and configuration: N/A
#- How you installed Lightning: pip
#- Running environment of LightningApp: cloud

More info

No response

cc @tchaton

@adamjstewart adamjstewart added bug Something isn't working needs triage Waiting to be triaged by maintainers labels Feb 14, 2023
@awaelchli awaelchli added 3rd party Related to a 3rd-party and removed needs triage Waiting to be triaged by maintainers labels Feb 15, 2023
@awaelchli
Copy link
Member

@Borda Do you know what's the alternative here?

@awaelchli awaelchli added this to the v1.9.x milestone Feb 15, 2023
@adamjstewart
Copy link
Contributor Author

I'm not super familiar with namespace packages, but based on the link in the warning message, it seems like you're supposed to set the namespace_packages field in setup.py and let setuptools handle namespacing instead of doing it manually in __init__.

@adamjstewart
Copy link
Contributor Author

Note that the the warning message changed slightly in setuptools 67.4:

DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('lightning_fabric')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`.

@adamjstewart
Copy link
Contributor Author

Any updates on this?

@awaelchli awaelchli added the help wanted Open to be worked on label Mar 17, 2023
@awaelchli
Copy link
Member

@Borda Should we do what @adamjstewart said #16756 (comment)?

@Borda
Copy link
Member

Borda commented Mar 17, 2023

I am not much familiar with namespace, let me check it

@adamjstewart
Copy link
Contributor Author

Update: setuptools 67.5 officially deprecates all of pkg_resources: https://setuptools.pypa.io/en/latest/history.html#v67-5-0

@adamjstewart adamjstewart changed the title DeprecationWarning: pkg_resources.declare_namespace DeprecationWarning: pkg_resources is deprecated as an API Oct 4, 2023
@tonybaloney
Copy link

See
https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#finding-namespace-packages for instructions on what to do.

TLDR if you require namespace packages (searching where there isn't nessecarily a __init__.py in every folder), use

from setuptools import find_namespace_packages

setup(
    # ...
    packages=find_namespace_packages(),
    # ...
)

Otherwise:

from setuptools import find_packages

setup(
    # ...
    packages=find_packages(),
    # ...
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party Related to a 3rd-party bug Something isn't working help wanted Open to be worked on priority: 1 Medium priority task
Projects
None yet
Development

No branches or pull requests

4 participants