pypa / virtualenv

Virtual Python Environment builder
https://virtualenv.pypa.io
MIT License
4.8k stars 1.03k forks source link

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

Closed mayeut closed 6 months ago

mayeut commented 8 months ago

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. https://github.com/python/cpython/issues/106045

Environment

Provide at least:

on: push: branches:

jobs: venv: runs-on: ubuntu-22.04 steps:

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']
ofek commented 7 months ago

Resolving symbolic links would also fix this issue: https://github.com/pypa/virtualenv/issues/2684

gaborbernat commented 7 months ago

PR welcome to address this is welcome 👍