Skip to content

Commit eabbdec

Browse files
committed
Avoid sys.path pollution when switching interpreters
Fixes #671
1 parent b7e489f commit eabbdec

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

virtualenv.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,13 @@ def main():
802802
file = __file__
803803
if file.endswith('.pyc'):
804804
file = file[:-1]
805-
popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
805+
# use exec() instead of passing the script name directly to avoid
806+
# sys.path pollution
807+
popen = subprocess.Popen(
808+
[interpreter,
809+
'-c',
810+
'import sys; del sys.argv[0]; s = sys.argv[0]; exec(open(s).read(), {"__file__": s, "__name__": "__main__"})',
811+
file] + sys.argv[1:], env=env)
806812
raise SystemExit(popen.wait())
807813

808814
if not args:

0 commit comments

Comments
 (0)