Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory change not occuring with setvirtualenvproject

I'm embracing VirtualEnvWrapper - and like what I see a lot. However as I try to get going I'm not seeing the behaviour I expect when trying to set up project directory association with virtual envs.

I've installed virtualenv and -wrapper. I can create envs and "workon" lists them fine. I can deactivate and rm them happily. So all appears functional. I read the docs regarding project mgmt. (Also a good video tutorial, and the desired proj association behaviour explained at 10:39 )

When I try to associate a work directory with an env, it accepts my cmds fine, but when I "workon" the project, it does not put me into my designated working directory.

e.g. I have a working area ~/Ross_code (and I've set this in my .bashrc as $PROJECT_HOME). In there is an existing project folder ~/Ross_code/superproj

So now I create an env with

mkvirtualenv superp

Then I go to my existing project dir and associate it with the env:

cd ~/Ross_code/superproj 
setvirtualenvproject
Setting project for superp to /Users/ross/Ross_code/superproj

Then I exited the virtual env with "deactivate" and reactivated with

workon superp

But the present working dir remains my ~/ folder.
I checked the .project file which seems to have been set properly by the call to setvirtualenvproject:

cdvirtualenv
more .project
/Users/ross/Ross_Code/superproj

but calling "workon" never sticks me into the expected spot. I thought maybe the env and the project directory needed to be of the same name, but that didn't make any difference either.

Any idea why that very attractive project association capability doesn't work for me?

-Ross.

LATER - More info: I tried to also use the mkproject command, which should create a directory for my code in the $PROJECT_HOME area, and create the virtualenv at the same time and associate them with each other.

Calling

mkproject junkproj

does in fact create the project directory nicely, and sticks me into the virtualenv, and cd's into the junkproj directory. But when I deactivate, and then "workon junkproj" again, I'm still left in my ~/ directory, rather than going into the project directory in $PROJECT_HOME

:(

like image 437
RossGK Avatar asked Feb 11 '23 03:02

RossGK


1 Answers

The problem here is that the newer versions (this hit me upgrading from ubuntu 14.04 to 16.04) of virtualenvwrapper use a slightly different protocol for the setvirtualenvproject parameters:

setvirtualenvproject [virtualenv_path project_path]

In order to make the association you want in any virtual env, be in the project folder and the virtualenv and use:

setvirtualenvproject $VIRTUAL_ENV .

The dot is for the present directory - or you can use the path of the directory you want workon to take you to. Once you do this workon will switch you to the folder you want and cdproject will work as expected.

If you used the old protocol, you'll have a .project file in your project folder - you can move this to the $VIRTUAL_ENV folder rather than invoking the command with the new protocol to make the association. The file just contains the project directory you want to associate with virtualenvwrapper shortcut commands like workon and cdproject.

like image 194
Paul Whipp Avatar answered Feb 16 '23 03:02

Paul Whipp