255

I am learning Python virtual environment. In one of my small projects I ran

pipenv run python myproject.py

and it created a virtualenv for me in C:\Users\USERNAME\.virtualenvs

I found it also created or modified some files under my project source code directory. I am just wondering how to cleanly delete this virtualenv and reverse my project back to a no-virtualenv state.

I am using python 3.6.4, and PyCharm.

Z.Wei
  • 3,658
  • 2
  • 17
  • 28

2 Answers2

539

You can run the pipenv command with the --rm option as in:

pipenv --rm

This will remove the virtualenv created for you under ~/.virtualenvs

See https://pipenv.kennethreitz.org/en/latest/cli/#cmdoption-pipenv-rm

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Pyramid Newbie
  • 6,865
  • 3
  • 24
  • 28
  • 6
    So ... that works if I still have the directory containing the `Pipfile`. But what if I've deleted it? – offby1 Jul 31 '18 at 23:28
  • 23
    @offby1 just manually delete it in the terminal by going to `~/.virtualenvs` and removing the directory. The directory is named after the project plus a hash of its location e.g. `projectname-Kovkq8ZR` – Tom Sep 13 '18 at 10:05
  • 9
    if there is a command to create an env there should be a command to remove one, not a switch. – Andrew Feb 15 '19 at 02:11
  • 1
    i want to delete a specific virtualenv instead of all, what will do? – Banee Ishaque K Apr 08 '19 at 15:09
  • 12
    @BaneeIshaqueK `pipenv --rm` does only remove the `virtualenv` for the associated `Pipfile` in the current directory. – Marco Sulla Oct 11 '19 at 12:59
  • It also works for the virtual environment created by `pipenv install` command. – Lin Du Dec 16 '19 at 05:14
  • 4
    @Tom for me it was in .local/share/virtualenvs/ – joel Jan 06 '20 at 16:46
  • Note this does not remove the associated `Pipfile` and `Pipfile.lock` files (in the current directory)! – xuiqzy Nov 04 '21 at 20:05
  • The link is broken, the old link from the history of the post works. – xuiqzy Nov 04 '21 at 20:16
50

I know that question is a bit old but

In root of project where Pipfile is located you could run

pipenv --venv

which returns

  • Linux/OS X:
/Users/your_user_name/.local/share/virtualenvs/model-N-S4uBGU
  • Windows:
C:\Users\your_user_name\.virtualenvs\model-N-S4uBGU

and then remove this env by typing

  • Bash/Zsh:
rm -rf /Users/your_user_name/.local/share/virtualenvs/model-N-S4uBGU
  • Powershell:
Remove-Item -Recurse -Force 'C:\Users\your_user_name\.virtualenvs\model-N-S4uBGU'
  • Command Prompt
rmdir /s "C:\Users\your_user_name\.virtualenvs\model-N-S4uBGU"
mikolaj semeniuk
  • 2,030
  • 15
  • 31
  • 1
    This is great! especially since sometimes I forgot which clones I use with powershell's pipenv and which with WSL so `pipenv --rm` is not good enough for me in some cases, thank you! – AmazingMiki Sep 02 '21 at 12:19
  • 1
    Note this does not remove the associated Pipfile and Pipfile.lock files (in the current directory)! – xuiqzy Nov 04 '21 at 20:14
  • 1
    Also delete the Pipfile and Pipfile.lock in the project directory by running the command "rm -rf Pipfile.lock Pipfile" in unix or linux system. I think in windows we need to use "del Pipfile" and "del Pipfile.lock" command to perform deleting those two files – Riswan Mar 02 '23 at 04:05