Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pipenv : how to force virtualenv directory?

Tags:

python

pip

pipenv

Actually, pipenv will install the virtualenv with a path like this :

$WORKON_HOME/<base_dir>-<hash>

Is it possible to have exactly the path I want, that is without the base_dir and the hash, for exemple :

/home/user/myapp_venv
like image 439
Eric Avatar asked May 30 '18 06:05

Eric


3 Answers

Apart from using a custom location, you can also install the virtualenv in your project's directory. Just add the following line in your .bashrc/.zshrc file:

export PIPENV_VENV_IN_PROJECT=1

Just wanted to let others know that there is another approach available too.

Should you keep the virtualenv inside or outside the project's directory is an opinionated question afterall.

like image 148
Dhruv Joshi Avatar answered Oct 23 '22 23:10

Dhruv Joshi


There is an undocumented feature of pipenv, it could locate virtualenv path from VIRTUAL_ENV environment variable, but you need to create virtualenv manually:

virtualenv /home/user/myapp_venv
VIRTUAL_ENV=/home/user/myapp_venv pipenv install
like image 30
georgexsh Avatar answered Oct 23 '22 21:10

georgexsh


There's an undocumented feature in pipenv: if you create a file named .venv in the project root with a path in it, pipenv will use that instead of an autogenerated path.

This, however, is more fit for cases when you already have an established set of environments that you wish to reuse. Otherwise, placing environments in arbitrary places is prone to create a mess eventually. pipenv relieves you from this task specifically to keep them all in one predictable place and eliminate accidental collisions from human error.

like image 12
ivan_pozdeev Avatar answered Oct 23 '22 22:10

ivan_pozdeev