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
"bad magic number" when Python 2's pyc file exists without py file #88135
Comments
Python 3 imports may fail if a Python 2 .pyc file exists without an accompanying .py file. ----- My project vendors code, and we recently updated "requests" to a drastically newer version. As part of this version change, This project is long-lived, and many people have imported After making this update, importing requests with Python 3 fails: Interestingly, deleting ----- I've attached a "reproduction" script that produces the directory structure and tweak required to cause the failure. |
Looking closer into this, it appears that Python 3 will still try to load non-pycache Location where I'll attach a patch to remove this pyc-loading for convenience, but I don't have enough context to be confident that it's the correct solution. |
Unless you find documentation that says otherwise, this an enhancement proposal for 3.11. If no core developer (other than me) jumps on this, you might use git blame to fine out who committed code in the area you proposed changing. |
I'm going to close this here - I currently don't have the cycles to push this forward. Besides, this issue only occurs in environments that are using both Python 2 and 3, and as Python 2's EOL date gets further in the past, the severity of this ticket decreases. For future readers, if you need a workaround for this exact problem, it was solved by my team with this import hook: https://hg.mozilla.org/mozilla-central/file/50e4a4e6975a7f828277a2b9c3cc9770a6c94107/build/mach_initialize.py#l630 |
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: