Okay, I think I have a fairly clever hack for fixing this.  Turns out we don't
really *need* sys.path[0] when virtualenv.py is re-invoked, so I just remove
it.  Tested and 'virtualenv -p python3 /tmp/xx' works great now.

Patch is attached.  I will also commit it to the team svn.

Index: patches/remove_syspath0_on_reinvoke.patch
===================================================================
--- patches/remove_syspath0_on_reinvoke.patch	(revision 0)
+++ patches/remove_syspath0_on_reinvoke.patch	(revision 0)
@@ -0,0 +1,24 @@
+Description: When reinvoked, sys.path[0] will point into /usr/share/pyshared
+ on Debian, which will cause the following import to pick up the wrong version
+ (i.e. the 2.7 version when -p python3 is used).  We don't need sys.path[0], so
+ just remove it permanently. 
+Author: Barry Warsaw <ba...@python.org>
+Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=625784
+Forwarded: not-needed
+--- a/virtualenv.py
++++ b/virtualenv.py
+@@ -469,6 +469,14 @@
+         project_name = 'distribute'
+         bootstrap_script = DISTRIBUTE_SETUP_PY
+         try:
++            # When reinvoked, sys.path[0] will point into /usr/share/pyshared
++            # on Debian, which will cause the following import to pick up the
++            # wrong version (i.e. the 2.7 version when -p python3 is used).
++            # We don't need sys.path[0], so just remove it permanently.  See
++            # Debian bug 625785.
++            if (os.environ.get('VIRTUALENV_INTERPRETER_RUNNING', '') == 'true'
++                and sys.path[0] == '/usr/share/pyshared'):
++                del sys.path[0]
+             # check if the global Python has distribute installed or plain
+             # setuptools
+             import pkg_resources
Index: patches/series
===================================================================
--- patches/series	(revision 16912)
+++ patches/series	(working copy)
@@ -1,2 +1,3 @@
 look_for_external_files.patch
 add_distribute.patch
+remove_syspath0_on_reinvoke.patch

Attachment: signature.asc
Description: PGP signature

Reply via email to