Search code examples
pythonvirtualenvvirtualenvwrapper

virtualenv wrapper custom directory?


How do I set the location for a certain virtual env in virtualenv wrapper?

I am happy for my existing and most of my future projects to still sit within

~/.virtualenv

but I want my web project virtual environment to sit within my web project folder.

Thanks


Solution

  • I'm afraid that wouldn't be possible. virtualenvwrapper is hard-coded to follow WORKON_HOME when searching for virtualenvs. There's no clean way to point a specific virtualenv to a certain location. The only workaround I can think of is ln -s-ing your virtualenv into WORKON_HOME, which is probably not what you're looking for.

    But if you want to use a virtualenv placed in an arbitrary location, you can simply just use virtualenv directly. Obviously you lose hooks like postactivate, predeactivate, etc., but it's not impossible to replace these.

    Edit: Environment variable hack

    One hack (as mentioned by James Mills), though, is to replace WORKON_HOME temporarily when you load the certain virtualenv. Just prefix you commands (mkvirtualenv, workon, etc.) with an environment variable override:

    $ WORKON_HOME=/where/you/want mkvirtualenv virtualenv_name
    

    And the virtualenv will be created in /where/you/want.