relocatable activate for bash, dash, zsh, ksh, fish, Windows #236

wants to merge 9 commits into


None yet
jpenney commented Mar 6, 2012 edited

Updated activate.bat,, and that set VIRTUAL_ENV based on where the the activate.* file is sourced or executed from.

See: #11

Also contains tempfile -> mktemp change from #8 since I needed to in order to verify the change.


Wow this is exactly what I need for one of my project when will this make it in to the official dev branch?


I'm really not a fan of this. I don't like --relocatable in the first place, it's implementation, or the pattern of virtualenv usage that it encourages. If I could go back in time and remove --relocatable from ever having been added to virtualenv, I'd do it in an instant.

One of the most difficult bits of keeping virtualenv maintained is maintaining all of the activation scripts. I'd like to be finding ways to simplify them, but this does the opposite - it makes them significantly more complex and makes it harder to verify their correctness.

I guess in the end I'm a -0 here. I'm not going to merge it, but I won't stand in the way if @jezdez wants to.


I should have also added that regardless, I very much appreciate the contribution and the time that went into it! Thank you.


Thanks. I actually agree fully that the stuff is messy (Windows and fish were pretty straightforward). I was hoping there was a nice portable solution, but it seems every shell handles it differently, which is a shame.

I have a specific case where I have a need for relocatable, but normally I don't use it either. Still these changes should be transparent if you are NOT using the relocatable stuff.


Yeah, they should be transparent, but just the added complexity alone worries me - I don't know what other bugs we might be introducing that we won't find out about until later, or maintenance difficulties down the road. Interested to know what @jezdez thinks.


Yeah, I agree with @carljm that the complexity of the activation scripts is bothersome.


Here is another suggestion for making activate.bat more relocatable:
It uses another approach for dynamically determining the directory of the virtual env and
it also changes the prompt. | 9 +++++----
virtualenv_embedded/activate.bat | 6 ++++--
2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/ b/
index 0ad059b..eede4d4 100755
--- a/
+++ b/
@@ -2148,10 +2148,11 @@ i4Un70/3X5WjwzZMlciUNff39a5T/N3difzB/qM0y71r7H5Wv4DubrNS4VPRvDPW/FmM/QUd6WEa

##file activate.bat
ACTIVATE_BAT = convert("""

##file deactivate.bat
diff --git a/virtualenv_embedded/activate.bat b/virtualenv_embedded/activate.bat
index 1b06941..4d58b98 100644
--- a/virtualenv_embedded/activate.bat
+++ b/virtualenv_embedded/activate.bat
@@ -1,5 +1,6 @@
@echo off
+for %%G in ("%~dp0..") do SET _BASE_DIR=%%~fG

if not defined PROMPT (
@@ -14,7 +15,8 @@ if defined _OLD_VIRTUAL_PYTHONHOME (

+for %%G in ("%~dp0..") do SET _DIR_NAME=%%~nG

if defined PYTHONHOME (


Can you ensure this is mergeable and I'll take another look.


Any traction on this?


+1 for this feature, it is very useful when you need to copy the virtual environment to another directory.

Python Packaging Authority member

I'm with @carljm I'm afraid. I don't like --relocatable (I'm not sure it even works on Windows, where the exe wrappers can't be updated) and so I don't see any value in added complexity to the activate scripts to support a usage I don't want to encourage.




It's really uncomfortable that this fairly complex behavioral change doesn't necessitate any changes to the test suite =/

Python Packaging Authority member

@bukzor you could call the test suite fairly non-existent atm, which is why :(

@dstufft dstufft referenced this pull request Jan 5, 2015

Rewrite virtualenv #697

0 of 5 tasks complete


As part of an effort to ease the contribution process and adopt a more standard workflow pip has switched to doing development on the master branch. However, this Pull Request was made against the develop branch so it will need to be resubmitted against master. Unfortunately, this pull request does not cleanly merge against the current master branch.

If you do nothing, this Pull Request will be automatically closed by @BrownTruck since it cannot be merged.

If this pull request is still valid, please rebase it against master (or merge master into it) and resubmit it against the master branch, closing and referencing the original Pull Request.

If you choose to rebase/merge and resubmit this Pull Request, here is an example message that you can copy and paste:

Updated activate.bat,, and that set VIRTUAL_ENV based on where the the activate.* file is sourced or executed from.

See: #11

Also contains tempfile -> mktemp change from #8 since I needed to in order to verify the change.


*This was migrated from pypa/virtualenv#236 to reparent it to the ``master`` branch. Please see original pull request for any previous discussion.*

This Pull Request was closed because it cannot be automatically reparented to the master branch and it appears to have bit rotted.

Please feel free to re-open it or re-submit it if it is still valid and you have rebased it onto master or merged master into it.

@BrownTruck BrownTruck closed this May 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment