82

I want Pipenv to make virtual environment in the same folder with my project (Django).

I searched and found the PIPENV_VENV_IN_PROJECT option but I don't know where and how to use this.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
DAMAR225
  • 1,993
  • 1
  • 13
  • 22

7 Answers7

106

PIPENV_VENV_IN_PROJECT is an environment variable, just set it (the value doesn't matter, but must not be empty). Make sure to export it so child processes of the shell can see it:

export PIPENV_VENV_IN_PROJECT=1

This causes the virtualenv to be created in the .venv directory next to the Pipfile file. Use unset PIPENV_VENV_IN_PROJECT to remove the option again.

You may want to see if the direnv project can be useful here. It'll set environment variables for you, automatically, when you enter your project directory, provided you created a .envrc file in the project directory and enabled the directory with direnv allow. You then can add any such export commands to that file.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • thanks for your replay , how can i set this environment variable ? i'm using ubuntu 18.04 server running on vps hosting ? sorry i'm a very newbie with ubuntu stuff – DAMAR225 Sep 27 '18 at 15:39
  • @DAMAR225: I gave you the syntax for a bash shell environment, just use that when you have a terminal open where you are executing the Pipenv commands. – Martijn Pieters Sep 27 '18 at 15:49
  • So what command should I run if I am using windows powershell? Thank you – Serdia Apr 19 '20 at 18:12
  • @Serdia: no idea, sorry, not a Windows user. – Martijn Pieters Apr 20 '20 at 20:30
  • Note, that if you install from a requirements.txt with `-r` you should first create the empty Pipfile, so that pipenv knows, next to where it should put .venv – Eike Sep 21 '22 at 12:57
  • @Eike: then why use pipenv at all? Just use `virtualenv .venv` to create the virtual env yourself. – Martijn Pieters Oct 07 '22 at 11:15
84

This maybe helps someone else. I found another easy way to solve this!

Just make an empty folder inside your project and name it .venv and pipenv will use this folder.

DAMAR225
  • 1,993
  • 1
  • 13
  • 22
5

Try

PIPENV_VENV_IN_PROJECT=1 pipenv sync -d
Weilao
  • 51
  • 1
  • 2
  • PIPENV_VERBOSITY=-1 PIPENV_VENV_IN_PROJECT=1 pipenv install --python 3.8.7 would give you a specific python version as well. Sync did not work for me. – Liquidgenius Jun 08 '21 at 21:05
4

In Three simple steps:

  1. export the variable as

    export PIPENV_VENV_IN_PROJECT=1

  2. Create a empty folder and file Pipfile

    mkdir .venv

    touch Pipfile

  3. Then execute

    pipenv shell

Vinoj John Hosan
  • 6,448
  • 2
  • 41
  • 37
3

For the fish shell, use:

set -Ux PIPENV_VENV_IN_PROJECT 1
Gringo Suave
  • 29,931
  • 6
  • 88
  • 75
3

For posterity's sake, if you find pipenv is not creating a virtual environment in the proper location, you may have an erroneous Pipfile somewhere, confusing the pipenv shell call - in which case I would delete it form path locations that are not explicitly linked to a repository.

xxyjoel
  • 551
  • 5
  • 7
2

This trick worked for me:

  • create an empty folder named .venv
  • create an empty file named Pipfile
  • Run pipenv shell there.
  • Thanks, this worked for me. to add, made sure to run >exit to exit the wrong virtual environment and then made sure to delete the wrong .venv Followed your first 2 steps Ran this instead: PIPENV_VENV_IN_PROJECT=true pipenv install --dev pipenv shell – yasbars Jul 10 '23 at 13:16