Repository: celery/celery

Issue:
Celery Import Error
<!--
Please use one of our issue templates.
We reserve the right to close bug reports or feature requests who don't use our templates.
-->
Not able to import Celery module when creating simple app.

from celery import Celery
ImportError: cannot import name 'Celery' from 'celery'

Additonal info:
This issue doesn't occur when we downgrade importlib-metadata to 4.12.0
Env details
![image](https://user-images.githubusercontent.com/55486262/193540909-f96e4503-44cf-45ed-b151-79af2cc6e12c.png)



Discussion:
Hey @marimuthuei :wave:,
Thank you for opening an issue. We will get back to you as soon as we can.
Also, check out our [Open Collective](https://opencollective.com/celery) and consider backing us - every little helps!

We also offer priority support for our sponsors.
If you require immediate assistance please consider sponsoring us.

What python version? Seems to occur only with python 3.7 #7784
Ok I guess because `importlib-metadata` is not installed when you install celery in a python 3.8 environment.
similar imports are failing (e.g. `current_app`) with the same behavior (works when downgrading `importlib-metadata`). Seems to only be in python 3.7.

Tests with py3.8 **and** importlib-metadata works for me.
its python3.7 env
This seems to be the cause: https://github.com/python/importlib_metadata/pull/405

```python
Successfully installed importlib_metadata-4.13.0
$ python
Python 3.7.9 (default, Jul  5 2021, 22:17:33) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from importlib_metadata import entry_points
>>> entry_points().get("celery.result_backends", list())
__main__:1: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
[]
```

So I guess we should fix

https://github.com/celery/celery/blob/59263b0409e3f02dc16ca8a3bd1e42b5a3eba36d/celery/utils/imports.py#L142-L145
The kombu package probably has the same problem

https://github.com/celery/kombu/blob/97e887605b21a110e0ec304913930a8115987c6a/kombu/utils/compat.py#L93

Resolving patch:
diff --git a/celery/bin/celery.py b/celery/bin/celery.py
--- a/celery/bin/celery.py
+++ b/celery/bin/celery.py
@@ -1,6 +1,7 @@
 """Celery Command Line Interface."""
 import os
 import pathlib
+import sys
 import traceback
 
 try:
@@ -75,7 +76,16 @@ def convert(self, value, param, ctx):
 APP = App()
 
 
-@with_plugins(entry_points().get('celery.commands', []))
+if sys.version_info >= (3, 10):
+    _PLUGINS = entry_points(group='celery.commands')
+else:
+    try:
+        _PLUGINS = entry_points().get('celery.commands', [])
+    except AttributeError:
+        _PLUGINS = entry_points().select(group='celery.commands')
+
+
+@with_plugins(_PLUGINS)
 @click.group(cls=DYMGroup, invoke_without_command=True)
 @click.option('-A',
               '--app',
diff --git a/celery/utils/imports.py b/celery/utils/imports.py
--- a/celery/utils/imports.py
+++ b/celery/utils/imports.py
@@ -141,7 +141,14 @@ def gen_task_name(app, name, module_name):
 
 
 def load_extension_class_names(namespace):
-    for ep in entry_points().get(namespace, []):
+    if sys.version_info >= (3, 10):
+        _entry_points = entry_points(group=namespace)
+    else:
+        try:
+            _entry_points = entry_points().get(namespace, [])
+        except AttributeError:
+            _entry_points = entry_points().select(group=namespace)
+    for ep in _entry_points:
         yield ep.name, ep.value
 
 


Test patch: