-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
Issue
The home & base-executable keys in pyvenv.cfg do not resolve symlinks using realpath() leading to a broken virtual environment in some cases.
Environment
Provide at least:
- OS: at least Linux
- GHA reproducer:
name: Python test bitness
on:
push:
branches:
- venv-reproducer
workflow_dispatch:
# allow manual runs on branches without a PR
jobs:
venv:
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: test
run: |
set -x
fail_venv=0
fail_virtualenv=0
sudo apt-get update &>/dev/null
sudo apt-get install -y python3-distutils &>/dev/null
python3 -m pip install virtualenv
python3 -m venv cp311-1
cat cp311-1/pyvenv.cfg
cp311-1/bin/python -sSEc 'import sys; print(sys.path)'
python3 -m virtualenv cp311-2
cat cp311-2/pyvenv.cfg
cp311-2/bin/python -sSEc 'import sys; print(sys.path)'
ln -sf $(which python3) /usr/local/bin/python3
/usr/local/bin/python3 -m venv cp311-3 || fail_venv=1
cat cp311-3/pyvenv.cfg
cp311-3/bin/python -sSEc 'import sys; print(sys.path)'
/usr/local/bin/python3 -m virtualenv cp311-4 || fail_virtualenv=1
cp311-4/bin/python -c 'import subprocess' || fail_virtualenv=1
cat cp311-4/pyvenv.cfg
cp311-4/bin/python -sSEc 'import sys; print(sys.path)'
exit $(( $fail_venv + $fail_virtualenv ))
Output
the cp311-4 is broken & uses the following pyvenv.cfg:
home = /usr/local/bin
implementation = CPython
version_info = 3.11.7.final.0
virtualenv = 20.25.0
include-system-site-packages = false
base-prefix = /opt/hostedtoolcache/Python/3.11.7/x64
base-exec-prefix = /opt/hostedtoolcache/Python/3.11.7/x64
base-executable = /usr/local/bin/python3
/usr/local/bin shall never be referenced in this file as /usr/local/bin/python3 is just a symlink on /opt/hostedtoolcache/Python/3.11.7/x64/bin/python3
importing subprocess fails because the computed sys.path is invalid for this interpreter (/usr/lib/python3.11/lib-dynload is invalid here):
['', '/opt/hostedtoolcache/Python/3.11.7/x64/lib/python311.zip', '/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11', '/usr/lib/python3.11/lib-dynload']