[New-bugs-announce] [issue16519] site.venv() should use abspath(executable)

Christian Heimes report at bugs.python.org
Wed Nov 21 08:58:54 CET 2012

New submission from Christian Heimes:

While I was testing #16499 I found a small bug in the venv code of the site module. The code in site.venv() doesn't use abspath() to sanitize the path to executable_dir. This leads to wrong behavior when a venv is created in the root of a hg checkout and the non-venv interpreter is called with a relative path:

(venv) heimes at hamiller:~/dev/python/cpython/venv$ ../python -c "import sys; print(sys.path)"
['', '/usr/local/lib/python34.zip', '/home/heimes/dev/python/cpython/Lib', '/home/heimes/dev/python/cpython/Lib/plat-linux', '/home/heimes/dev/python/cpython/build/lib.linux-x86_64-3.4-pydebug', '/home/heimes/dev/python/cpython/venv/lib/python3.4/site-packages']

The fix is simple, straight forward and totally harmless:
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -484,7 +484,7 @@
         executable = os.environ['__PYVENV_LAUNCHER__']
         executable = sys.executable
-    executable_dir, executable_name = os.path.split(executable)
+    executable_dir, executable_name = os.path.split(os.path.abspath(executable))
     site_prefix = os.path.dirname(executable_dir)
     sys._home = None
     if sys.platform == 'win32':

components: Interpreter Core
messages: 176043
nosy: christian.heimes
priority: normal
severity: normal
status: open
title: site.venv() should use abspath(executable)
type: behavior
versions: Python 3.3, Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list