Serdia
Serdia

Reputation: 4428

How to make pipenv install virtual environment in project folder on Windows 10

I want to fully understand how pipenv works. I created my project and would like virtual environment also be in same project folder. However pipenv installs virtual environment in C:\Users\username\.virtualenvs.

enter image description here

With that, if I change the name or location of my project path, the virtual environment will be lost.

So how can I install virtual environment inside project folder? I read about setting variable PIPENV_VENV_IN_PROJECT but I did not understand where and how should I do that using Powershell in windows.

Can somebody advise?

Upvotes: 4

Views: 7210

Answers (3)

Raul Chiarella
Raul Chiarella

Reputation: 712

Ok. I was just testing here, and the following things did'nt work:

  • set PIPENV_VENV_IN_PROJECT=1
  • Creating .venv folder and running pipenv shell did work, sort of, but since, in theory, this is manual work instead of automating a Python environment, I did'nt consider it as a solution.

The actual solution for me was:

Just Opened PowerShell and typed $env:PIPENV_VENV_IN_PROJECT=1 with a PowerShell Terminal open inside the project folder, and executed pipenv install. This worked and stopped creating .venvs on other User Profile folder.

For me this was the better approach since I am trying to automate this install using Docker Composer.

PowerShell with VENV inside my Project.

TL;DR;

cd <project_folder>
$env:PIPENV_VENV_IN_PROJECT=1
pipenv install

Upvotes: 0

Saketh Chandra
Saketh Chandra

Reputation: 41

You should add PIPENV_VENV_IN_PROJECT=1 to the Windows 10 User variable

Check out this for step by step process link where I mentioned the process with images

if you can't open: https://gist.github.com/Saketh-Chandra/28ac93aca0afb8a627ef66edaf575b0d

Upvotes: 0

Indrid
Indrid

Reputation: 1192

Create a .venv folder in your project root. Then run:

pipenv shell

Obviously run that from a terminal session in your project root. Pipenv should check to see if there is an empty .venv and if it finds one it should blow your virtual environment into that.

Upvotes: 10

Related Questions