-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[BUG] ImportError when using importlib
with setuptools 60.9.0+
#3292
Comments
Thank you very much @edmorley for reporting this. What seems to be happening here is that this version of It seems that any exception raised while processing I think what we can do here is to add a warning about the incompatibility (right now setuptools depend on This way even when the exception is supressed, the users will still be able to see the warning and act accordingly. What do you think? |
No problem - this was definitely an interesting one to track down. It only occurs with a precise combination of versions of four packages + Python version! If the Celery import is swapped for something else (eg
What would this warning trigger on?
I trust your wisdom! :-) |
Celery seems to be using some dynamic programming techniques for importing its internal components. My guess is that the
This would be triggered when the error in #3293 is detected. So what would happen is:
The warning that I have in mind, is something along the lines of:
|
That sounds great! :-) |
I tried the following to test the open PR: > docker run --rm -it python:3.7.13 bash
echo -e "from django.core.wsgi import get_wsgi_application\nfrom celery import Celery" > testcase.py
pip install 'setuptools @ git+https://github.com/abravalheri/setuptools@issue-3292'
pip install celery==5.2.2 Django==3.2.8 importlib-metadata==0.20
python -c 'import importlib; importlib.import_module("testcase")' The new output is: /usr/local/lib/python3.7/site-packages/setuptools/_importlib.py:23: UserWarning: `importlib-metadata` version is incompatible with `setuptools`.
This problem is likely to be solved by installing an updated version of `importlib-metadata`.
warnings.warn(msg) # Ensure a descriptive message is shown.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/testcase.py", line 2, in <module>
from celery import Celery
ImportError: cannot import name 'Celery' from 'celery' (/usr/local/lib/python3.7/site-packages/celery/__init__.py) It is not much, but at least the users can see the recommendation to update |
@edmorley, I understand that this solution is not ideal, sorry for that 😢 Currently Eventually we will be able to use the stdlib's Setuptools cannot have real dependencies (instead we have to bundle them). This means that |
Totally understand! I think that warning will be sufficient - it at least gives end-users some bread-crumbs to follow so they can resolve the issue :-) |
To anyone else encountering this error, make sure the Windows Media Feature Pack is installed on your computer. If you have the legacy Windows Media Player, you have it, but I was encountering this error repeatedly no matter what I did until I installed it. Go to Settings, Apps, Optional Features, then select it from the list and click next. wait for it to do it's thing then restart to finish installation |
setuptools version
setuptools==62.1.0
(The repro below uses the latest setuptools version, however, the first affected version was
setuptools==60.9.0
)Python version
Python 3.7
OS
Docker image
python:3.7.13
which is Debian 11 (it also occurs on Ubuntu on Heroku)Additional environment information
Reduced
requirements.txt
:Description
Between setuptools 60.8.2 and 60.9.0, a previously working Django project now fails when using
importlib.import_module()
:In the original project (which was from a customer), the
importlib.import_module()
usage was inside gunicorn, when it loads the provided WSGI application file. However, I've removed gunicorn (and much of the rest of the project) as part of creating a reduced testcase.The changes between those two setuptools versions are:
v60.8.2...v60.9.0
In addition to the workaround of downgrading setuptools to
60.8.2
, I also found that making any of the following changes (each in isolation) prevents the error from occurring:Expected behavior
Either:
importlib-metadata
versions.How to Reproduce
docker run --rm -it python:3.7.13 bash
echo -e "from django.core.wsgi import get_wsgi_application\nfrom celery import Celery" > testcase.py
pip install setuptools==62.1.0
pip install celery==5.2.2 Django==3.2.8 importlib-metadata==0.20
python -c 'import importlib; importlib.import_module("testcase")'
Output
The text was updated successfully, but these errors were encountered: