New submission from Barry A. Warsaw:
I haven't really thought about this deeply but I've observed that there are
lots of cases where a user will report getting an ImportError trying to import
a name from a module, where it turns out that the problem is that the module is
coming from an unexpected location. Examples include pip installed packages
overriding system packages, or unexpected vendorized wheels.
The standard first response is typically, "can you please run this to tell us
where the foo library is coming from?" E.g.
```
^^ this is indicative of an old version of urllib3. Can you please double
check whether you have an old urllib3 installed e.g. in /usr/local or ~/.
Testing:
$ python3 -c 'import urllib3; print(urllib3.__file__)'
should return:
/usr/lib/python3/dist-packages/urllib3/__init__.py
and might tell you where else a locally installed urllib3 is to be found if it
doesn't return that value.
```
It would be kind of useful if the original ImportError showed you where the
module came from (i.e. its __file__), if such information can be discerned.
E.g.:
```
>>> import requests; requests.__version__.split('.')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line
61, in <module>
from .packages.urllib3.exceptions import DependencyWarning
ImportError: cannot import name DependencyWarning from
requests.packages.urllib3.exceptions
(/usr/local/lib/python3.5/site-packages/requests/packages/urllib3.py)
```
If you saw that in a bug report, you'd almost immediately know that the user
has some local override that's potentially causing the problem.
----------
components: Interpreter Core
messages: 287708
nosy: barry
priority: normal
severity: normal
status: open
title: A more helpful ImportError message
versions: Python 3.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue29546>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com