-
-
Notifications
You must be signed in to change notification settings - Fork 30.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
ImportError: bad magic number in ... does not indicate where is that file located #90991
Comments
Recently I've been debugging a very nasty bug report that looked like this: Traceback (most recent call last):
File "/usr/bin/jupyter-notebook", line 5, in <module>
from notebook.notebookapp import main
File "/usr/lib/python3.10/site-packages/notebook/notebookapp.py", line 78, in <module>
from .services.kernels.kernelmanager import MappingKernelManager, AsyncMappingKernelManager
File "/usr/lib/python3.10/site-packages/notebook/services/kernels/kernelmanager.py", line 18, in <module>
from jupyter_client.session import Session
File "/usr/lib/python3.10/site-packages/jupyter_client/session.py", line 41, in <module>
from jupyter_client.jsonutil import extract_dates, squash_dates, date_default
File "/usr/lib/python3.10/site-packages/jupyter_client/jsonutil.py", line 10, in <module>
from dateutil.parser import parse as _dateutil_parse
File "/usr/lib/python3.10/site-packages/dateutil/parser/__init__.py", line 2, in <module>
from ._parser import parse, parser, parserinfo, ParserError
File "/usr/lib/python3.10/site-packages/dateutil/parser/_parser.py", line 42, in <module>
import six
ImportError: bad magic number in 'six': b'\x03\xf3\r\n' For details, see https://bugzilla.redhat.com/2057340 and benjaminp/six#359 What would really make things much easier to understand would be if the exception mentioned what is the path of 'six'. Consider this example: A rogue .py file in /usr/bin: $ sudo touch /usr/bin/copy.py Programs fail with: Traceback (most recent call last):
File "/usr/bin/...", line ..., in <module>
...
ImportError: cannot import name 'deepcopy' from 'copy' (/usr/bin/copy.py) Immediately I can see there is /usr/bin/copy.py which is probably not supposed to be there. However, when it is a pyc instead: $ sudo touch /usr/bin/copy.pyc Programs fail with: Traceback (most recent call last):
File "/usr/bin/...", line ..., in <module>
...
ImportError: bad magic number in 'copy': b'' Now I have no idea where "copy" is. The is a request for that exception to give that infomartion. |
Apparently, the exception already contains a path attribute with exactly the kind of information I'd like to see. What if the message was: ImportError: bad magic number in '/usr/bin/six.pyc': b'\x03\xf3\r\n' Would that be accepted as a PR? Should I discuss this on the mailing list? |
I assume a PR review should be enough. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: