python-build-standalone: [bug]: `venv` creation fails on `linux-musl` builds
I installed a standalone build with mise, but I’m unable to create virtual environments.
Error
$ python -m venv .venv
Error: Command '['/home/dan/check/.venv/bin/python', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
Info
$ python
Python 3.12.3 (main, Apr 15 2024, 18:29:24) [Clang 14.0.3 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ which python
/home/dan/.local/share/mise/installs/python/latest/bin/python
$ which pip
/home/dan/.local/share/mise/installs/python/latest/bin/pip
$ pip list
Package Version
---------- -------
pip 24.0
setuptools 69.1.0
$ pip debug
WARNING: This command is only meant for debugging. Do not use this with automation for parsing and getting these details, since the output and options of this command may change without notice.
pip version: pip 24.0 from /home/dan/.local/share/mise/installs/python/latest/lib/python3.12/site-packages/pip (python 3.12)
sys.version: 3.12.3 (main, Apr 15 2024, 18:29:24) [Clang 14.0.3 ]
sys.executable: /home/dan/.local/share/mise/installs/python/latest/bin/python3.12
sys.getdefaultencoding: utf-8
sys.getfilesystemencoding: utf-8
locale.getpreferredencoding: UTF-8
sys.platform: linux
sys.implementation:
name: cpython
'cert' config value: Not specified
REQUESTS_CA_BUNDLE: None
CURL_CA_BUNDLE: None
pip._vendor.certifi.where(): /home/dan/.local/share/mise/installs/python/latest/lib/python3.12/site-packages/pip/_vendor/certifi/cacert.pem
pip._vendor.DEBUNDLED: False
vendored library versions:
CacheControl==0.13.1
colorama==0.4.6
distlib==0.3.8
distro==1.8.0
msgpack==1.0.5
packaging==21.3
platformdirs==3.8.1
pyparsing==3.1.0
pyproject-hooks==1.0.0
requests==2.31.0
certifi==2023.07.22
chardet==5.1.0
idna==3.4
urllib3==1.26.17
rich==13.4.2 (Unable to locate actual module version, using vendor.txt specified version)
pygments==2.15.1
typing_extensions==4.7.1 (Unable to locate actual module version, using vendor.txt specified version)
resolvelib==1.0.1
setuptools==68.0.0 (Unable to locate actual module version, using vendor.txt specified version)
six==1.16.0
tenacity==8.2.2 (Unable to locate actual module version, using vendor.txt specified version)
tomli==2.0.1
truststore==0.8.0
webencodings==0.5.1 (Unable to locate actual module version, using vendor.txt specified version)
Compatible tags: 42
cp312-cp312-linux_x86_64
cp312-abi3-linux_x86_64
cp312-none-linux_x86_64
cp311-abi3-linux_x86_64
cp310-abi3-linux_x86_64
cp39-abi3-linux_x86_64
cp38-abi3-linux_x86_64
cp37-abi3-linux_x86_64
cp36-abi3-linux_x86_64
cp35-abi3-linux_x86_64
...
[First 10 tags shown. Pass --verbose to show all.]
What’s wrong. How do I fix it?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (8 by maintainers)
OK, I think this bug should be retitled: “
venvcreation fails onlinux-muslbuilds”. The cause is the issue with an unpatched embedded pip wheel as described above. The fix is… not obvious to me.There is a DIFFERENT question which is: why is
miseinstallinglinux-muslprecompiled Python builds on some unsuspecting Ubuntu systems (which definitely use glibc)? But, that’s a mise issue, not a python-build-standalone issue.heyyyy I think this old bug is related!
In python-build-standalone there’s a patch to the linux cpython build which exists to work around an issue that was never properly fixed where a non-dynamically-linked Python couldn’t bootstrap pip:
That lives on BUT apparently doesn’t apply to the
pip-24.0-py3-none-any.whlthat’s bundled withensurepipand gets used for venv creation:Note the lack of any try/except around the
ctypes.CDLL(None)call – the patch is not applied there. So that’s how it breaks:ensurepipuses its bundled, unpatchedpipwhl to install itselfpipwhl tries various ways to get the glibc versionCS_GNU_LIBC_VERSIONaren’t setpipwhl tries to usectypes.CDLL(None)without a guardMy question is how does this ever work? Clearly it works for @mustafa0x and for that matter used to work for me until recently. Is there some odd path I and @yozachar both followed that leads to us tripping over this pothole?
Ok, I added this in pip and it has now merged upstream; and we have a patch in
python-build-standaloneitself, so that’s the best we can do IIUC.I can try to submit a PR for this in pip.