This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mitchhentges
Recipients mitchhentges
Date 2021-04-28.20:36:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1619642212.93.0.461785778702.issue43969@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-04-28 20:36:52mitchhentgessetrecipients: + mitchhentges
2021-04-28 20:36:52mitchhentgessetmessageid: <1619642212.93.0.461785778702.issue43969@roundup.psfhosted.org>
2021-04-28 20:36:52mitchhentgeslinkissue43969 messages
2021-04-28 20:36:52mitchhentgescreate