This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: site.venv() should use abspath(executable)
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, eric.araujo, python-dev, vinay.sajip
Priority: normal Keywords:

Created on 2012-11-21 07:58 by christian.heimes, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg176043 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2012-11-21 07:58
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@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__']
     else:
         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':
msg176219 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-11-23 19:22
New changeset fe2200c1c2d3 by Vinay Sajip in branch '3.3':
Issue #16519: Used os.path.abspath, removed unnecessary code for executable_name.
http://hg.python.org/cpython/rev/fe2200c1c2d3

New changeset a874c4a6ad5f by Vinay Sajip in branch 'default':
Closes #16519: Merged fix from 3.3.
http://hg.python.org/cpython/rev/a874c4a6ad5f
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60723
2012-11-23 19:22:49python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg176219

resolution: fixed
stage: resolved
2012-11-23 17:15:28eric.araujosetnosy: + vinay.sajip, eric.araujo
2012-11-21 07:58:54christian.heimescreate