Make Pipenv create the virtualenv in the same folder

Question:

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.

Asked By: DAMAR225

||

Answers:

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.

Answered By: Martijn Pieters

For the fish shell, use:

set -Ux PIPENV_VENV_IN_PROJECT 1
Answered By: Gringo Suave

Try

PIPENV_VENV_IN_PROJECT=1 pipenv sync -d
Answered By: Weilao

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.

Answered By: DAMAR225

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.

Answered By: xxyjoel

This trick worked for me:

  • create an empty folder named .venv
  • create an empty file named Pipfile
  • Run pipenv shell there.
Answered By: Abhi Ranjan

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

Answered By: Vinoj John Hosan
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.