94

How to can get the path of virtualenv in pipenv?

can configure it to use a custom path for newly created virtualenv?

pppery
  • 3,731
  • 22
  • 33
  • 46
amir
  • 2,443
  • 3
  • 22
  • 49

5 Answers5

165

The following should give you the paths

$ pipenv --where
/home/wonder/workspace/myproj
$ pipenv --venv
/home/wonder/PyEnvs/myproj-BKbQCeJj
Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
Sewagodimo Matlapeng
  • 2,136
  • 2
  • 11
  • 12
  • 13
    I also find it sometimes useful to do `pipenv run which python` to make sure I'm using the Python I want to use. – Konstantin Dec 26 '18 at 20:18
16

Adding to Sewagodimo Matlapeng's answer for the second part of the question:

can configure it to use a custom path for newly created virtualenv?

According to documentation, you can set the base location for the virtualenvs with the environment variable WORKON_HOME. If you want to place the virtualenv specifically in <project>/.venv, set the environment variable PIPENV_VENV_IN_PROJECT.

e.g., running:

export WORKON_HOME=/tmp
pipenv install

Would place the virtualenv in /tmp/<projectname>-<hash>.

Jakub Kukul
  • 12,032
  • 3
  • 54
  • 53
Omer Anson
  • 310
  • 2
  • 8
3

You can check the documentation in "Usage" section:

https://github.com/pypa/pipenv#usage

You can find these two options:

  • --where Output project home information.
  • --venv Output virtualenv information.

The option "--venv" gives you the virtualenv path.

Or better here:

https://github.com/pypa/pipenv#locate-the-virtualenv

BR

JoPinc
  • 31
  • 2
0

I create a command to handle this:

https://github.com/tw-yshuang/Ubuntu-Setup-Scripts/blob/8917578f9ad95be03f48608b7068337215d33f92/config/.customfunction#L12

From line 12 ~ 105

Usage: pipenv_correspond [OPTION]

OPTION:
  ls,  --list                list all the corresponding projects_root & venvs
  uls, --useless             list all the not existing projects_roots that still have corresponding venvs
  npr, --no-project-root     hide projects_root
  rm,  --remove              remove all the venvs from command: "ls" or "uls", deafult is use "uls"

# example
$ pipenv_correspond ls

There have some options that suggest you enable this command:

  1. Recommend, create a ~/.customfunction file and paste it, then use this command:
$ echo '# customfunction\nsource ~/.customfunction' >> <shell_profile>

shell_profile, e.g. ~/.bash_profile, ~/.zshrc

  1. you can copy this code from line 12 ~ 105 to your shell_profile.
ys_huang
  • 83
  • 1
  • 5
-2

You can simple use following command:

pipenv --where
  • 1
    This does not answer the question. --where gives the location of the project, not the virtualenv. – Shayne Feb 05 '23 at 12:26