New submission from Mitchell Hentges <mitch9...@gmail.com>:

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, `requests/packages/__init__.py` was removed, 
and  `requests/packages.py` was added.

This project is long-lived, and many people have imported `requests` with 
Python 2. So, `requests/packages/__init__.pyc` exists.

After making this update, importing requests with Python 3 fails:
`ImportError: bad magic number in 'parent.child': b'\x03\xf3\r\n'`

Interestingly, deleting `requests/packages/__init__.pyc` allows Python 3 to 
work again.

-----

I've attached a "reproduction" script that produces the directory structure and 
tweak required to cause the failure.
I'm running Python 2.7.18 and Python 3.9.1.

----------
components: Interpreter Core
files: repro.sh
messages: 392254
nosy: mitchhentges
priority: normal
severity: normal
status: open
title: "bad magic number" when Python 2's pyc file exists without py file
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49997/repro.sh

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43969>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to