Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pipenv: how to activate virtual environment by specifying name or path?

pipenv has a design centered around projects having their own venvs. What if I have a generic venv that I want to use for scripting or to be shared with other projects and therefore I would like it to be activate while the current directory is pointing anywhere in the system. How can I achieve this? I looked up the docs and I couldn't see a way to do it.

In conda, one can simply activate an environment by specifying its name, no matter whats the current directory is. Even virtualenv can do the same but you have to specify the path.

like image 288
Alex Deft Avatar asked Oct 16 '25 04:10

Alex Deft


1 Answers

At the directory where Pipfile resides, find the path to the environment:

pipenv --venv

Copy that path, for example /Users/yourname/.local/share/virtualenvs/yourproject-7qj8f3ed. Then in any other folder you can activate the venv with source, e.g.:

source /Users/yourname/.local/share/virtualenvs/yourproject-7qj8f3ed/bin/activate

You could also put an alias in bash.rc, etc to make a shortcut to that command.

like image 139
Bret Hess Avatar answered Oct 17 '25 19:10

Bret Hess