DAMAR225
DAMAR225

Reputation: 2437

Make Pipenv create the virtualenv in the same folder

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.

Upvotes: 96

Views: 68926

Answers (9)

SalsaJJ
SalsaJJ

Reputation: 374

You can also set the variables on your terminal's settings to avoid doing it on each different project.

In bash you can add these lines to~/bashrc (or ~/bash_profile):

export PIPENV_VENV_IN_PROJECT=1

Or from terminal:

echo 'export PIPENV_VENV_IN_PROJECT=1' >> ~/.bashrc

source ~/.bashrc

Of course this is different for zsh and other terminals but you can search for the same on them.

Upvotes: 0

Glemi
Glemi

Reputation: 725

You can also create a file named .env in your project root folder and include this line:

PIPENV_VENV_IN_PROJECT=1

Pipenv will recognize this file and automatically load all key-value pairs defined in it as environment variables before proceeding, as documented here. This has the same effect as manually defining an environment variable beforehand, except you have to do it only once and it works on any platform.

Defining environment variables in such a "dotenv" file is a fairly widely recognized convention and supported by many tools. See this article for further explanation.

Upvotes: 2

Vinoj John Hosan
Vinoj John Hosan

Reputation: 6853

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

Upvotes: 9

Abhi Ranjan
Abhi Ranjan

Reputation: 61

This trick worked for me:

  • create an empty folder named .venv
  • create an empty file named Pipfile
  • Run pipenv shell there.

Upvotes: 5

Martijn Pieters
Martijn Pieters

Reputation: 1121196

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.

Upvotes: 119

DAMAR225
DAMAR225

Reputation: 2437

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.

Upvotes: 108

xxyjoel
xxyjoel

Reputation: 591

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.

Upvotes: 3

Weilao
Weilao

Reputation: 61

Try

PIPENV_VENV_IN_PROJECT=1 pipenv sync -d

Upvotes: 6

Gringo Suave
Gringo Suave

Reputation: 31860

For the fish shell, use:

set -Ux PIPENV_VENV_IN_PROJECT 1

Upvotes: 4

Related Questions