Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

venv base-executable path does not resolve symlinks using realpath() #2682

Closed
mayeut opened this issue Jan 14, 2024 · 2 comments · Fixed by #2686
Closed

venv base-executable path does not resolve symlinks using realpath() #2682

mayeut opened this issue Jan 14, 2024 · 2 comments · Fixed by #2686
Labels

Comments

@mayeut
Copy link
Member

mayeut commented Jan 14, 2024

Issue

The home & base-executable keys in pyvenv.cfg do not resolve symlinks using realpath() leading to a broken virtual environment in some cases.

c.f. python/cpython#106045

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']
@mayeut mayeut added the bug label Jan 14, 2024
@mayeut mayeut changed the title venv base path does not resolve symlinks using realpath() venv base-executable path does not resolve symlinks using realpath() Jan 14, 2024
@ofek
Copy link
Contributor

ofek commented Jan 22, 2024

Resolving symbolic links would also fix this issue: #2684

@gaborbernat
Copy link
Contributor

PR welcome to address this is welcome 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants