Emerge of a few python packages fails with e.g. the following: ImportError: bad magic number in 'setuptools': b'\x03\xf3\r\n' Packages currently exhibiting this for me include: dev-python/markupsafe dev-python/cffi dev-python/bcrypt dev-python/cryptography Reproducible: Always Steps to Reproduce: 1. emerge -tv1 dev-python/markupsafe Actual Results: * python3_7: running distutils-r1_run_phase distutils-r1_python_compile python3.7 setup.py build -j 5 Traceback (most recent call last): File "setup.py", line 172, in <module> from setuptools import setup, Distribution, Extension ImportError: bad magic number in 'setuptools': b'\x03\xf3\r\n' Expected Results: Expected a successful emerge.
Created attachment 652440 [details] Build log
Created attachment 652442 [details] emerge --info
Created attachment 652444 [details] emerge -pqv
It seems likely to me your setuptools is corrupt. What happens if you re-emerge (with -1) it? I would also be worried about other files being corrupt.
That occurred to me too. Unfortunately re-emerging setuptools was not curative. In fact, re-emerging python as well as all other installed python modules did not help. Since this does not occur on another very similarly configured system, I too suspect corruption somewhere, but I have no idea where or how to correct it.
Turns out that the packages in question had been emerged with FEATURES="buildpkg". Removing the existing binary package tarballs from the packages directory allowed the emerge to succeed. I now wonder whether the binary packages that were previously built should have been deemed a system match. Seems to me that they shouldn't have, but it's unclear to me how portage could determine that.
The root cause of this ended up being a misguided PYTHONPATH setting in root's .bashrc which wrongly put an old python library directory at the front of the list. Upon removing that footgun, all proceeds well.