573

I created an environment with the following command: virtualenv venv --distribute

I cannot remove it with the following command: rmvirtualenv venv - This is part of virtualenvwrapper as mentioned in answer below for virtualenvwrapper

I do an lson my current directory and I still see venv

The only way I can remove it seems to be: sudo rm -rf venv

Note that the environment is not active. I'm running Ubuntu 11.10. Any ideas? I've tried rebooting my system to no avail.

wulymammoth
  • 5,981
  • 3
  • 15
  • 19
  • 25
    Just remove the directory. – nathancahill Jun 12 '12 at 21:57
  • honk: sudo rmvirtualenv venv is not a valid command. Not sure why I thought a reboot would help. I'm fairly new, to be a honest. – wulymammoth Jun 12 '12 at 21:57
  • 30
    Note that `rmvirtualenv` comes with virtualenvwrapper. You need that installed to make it work. – skytreader Apr 07 '13 at 04:34
  • 5
    Note that you can also remove all currently installed packages, but keep the virtual environment itself if you have virtualenvwrapper installed: `$ virtualenv --clear path_to_my_venv`. I use this from time to time to make sure I don't have anything manually installed, like an old dependency no longer in `requirements.txt`. – Taylor Edmiston Apr 15 '15 at 16:08
  • 1
    The `sudo` should not be necessary under normal circumstances. The whole point of a virtual environment is that you can manipulate it using your regular user account. – tripleee Apr 13 '19 at 14:46
  • As of `virtualenvwrapper-4.8.4-1` (year 2019!), the command `rmvirtualenv` does the whole job as expected. No need to do a `rm -rf VENV`. – sphakka Jun 12 '19 at 13:07
  • Note for future readers that --distribute is deprecated (https://virtualenv.pypa.io/en/stable/reference/#cmdoption-distribute) – Simon D Sep 20 '19 at 02:22
  • Nice question you asked. This question really helpful for those who are newcomer. – AMIC MING Dec 19 '19 at 17:13

17 Answers17

519

"The only way I can remove it seems to be: sudo rm -rf venv"

That's it! There is no command for deleting your virtual environment. Simply deactivate it and rid your application of its artifacts by recursively removing it.

Note that this is the same regardless of what kind of virtual environment you are using. virtualenv, venv, Anaconda environment, pyenv, pipenv are all based the same principle here.

KostasX
  • 2,364
  • 1
  • 12
  • 21
Thomas Anthony
  • 5,405
  • 1
  • 12
  • 7
  • 16
    It's worth noting that if you are using pip to install dependencies, you might want to pip freeze a dependency list and keep at the top level directory. If you later choose to deploy your application, you won't have a bit of trouble. – Thomas Anthony Jun 12 '12 at 22:18
  • 7
    Why is this accepted and with this much votes, when the correct answer is just bellow? Maybe this was for an older version of virtualenvwarpper – jsbueno Aug 28 '15 at 15:11
  • 10
    @jsbueno He was using virtualenv, not virtualenvwrapper (they are not the same program). At the time, virtualenv provided no interface for clean up; you had to do it yourself. – Thomas Anthony Jan 23 '16 at 02:12
  • 3
    If you've created a virtualenv in a git repo (and the files are not ignored): `git clean -dffx` – Rex Hardin Feb 22 '18 at 03:35
  • Works for me in Win10. I just deactivated the env and then deleted all the folders/files. – Doug J. Huras Jul 05 '20 at 16:37
178

Just to echo what @skytreader had previously commented, rmvirtualenv is a command provided by virtualenvwrapper, not virtualenv. Maybe you didn't have virtualenvwrapper installed?

See VirtualEnvWrapper Command Reference for more details.

Devy
  • 8,077
  • 6
  • 55
  • 55
123

Use rmvirtualenv

Remove an environment, in the $WORKON_HOME.

Syntax:

rmvirtualenv ENVNAME

You must use deactivate before removing the current environment.

$ rmvirtualenv my_env

Reference: http://virtualenvwrapper.readthedocs.io/en/latest/command_ref.html

aydow
  • 3,081
  • 1
  • 18
  • 33
Antoniazzi
  • 1,392
  • 1
  • 8
  • 9
96

You can remove all the dependencies by recursively uninstalling all of them and then delete the venv.

Edit including Isaac Turner commentary

source venv/bin/activate
pip freeze > requirements.txt
pip uninstall -r requirements.txt -y
deactivate
rm -r venv/
Dawn T Cherian
  • 3,924
  • 2
  • 18
  • 31
  • 3
    I think you're missing a `deactivate` before the `rm -r venv/` – Isaac Turner Dec 07 '16 at 15:17
  • 2
    And *critically* only do this if you are not sharing the system's `pip`! (Otherwise you will uninstall all of your system packages.) – orome Jan 09 '18 at 17:29
  • 6
    Actually there should be no need to separately `pip uninstall` if you are removing all the packages by way of `rm` anyway. Skipping that stepealso avoids the risk pointed out in the previous comment. – tripleee Apr 13 '19 at 14:43
46

Simply remove the virtual environment from the system.There's no special command for it

rm -rf venv
Naveen Agarwal
  • 830
  • 7
  • 7
  • 2
    Works on me. Make sure to deactivate first if your virtual environment is still running. (your virtual env)>deactivate >rm -rf "your virtual env" – tthreetorch Dec 02 '19 at 02:22
  • I find that the `-f` flag is not needed. I prefer to avoid that flag when possible. – Will Jun 11 '20 at 17:02
35

from virtualenv's official document https://virtualenv.pypa.io/en/stable/userguide/

Removing an Environment

Removing a virtual environment is simply done by deactivating it and deleting the environment folder with all its contents:

(ENV)$ deactivate
$ rm -r /path/to/ENV
Konrad Borowski
  • 9,885
  • 2
  • 50
  • 68
N.Lee
  • 824
  • 7
  • 13
  • 1
    @Sébastien No, you should not need `sudo` or similar privileges unless you also used them to set up the environment in the first place, which would usually be an error. – tripleee Apr 13 '19 at 14:40
  • The link in your answer is currently broken. – Will Jun 11 '20 at 17:03
31

If you are using pyenv, it is possible to delete your virtual environment:

$ pyenv virtualenv-delete <name>
9

1. Remove the Python environment

There is no command to remove a virtualenv so you need to do that by hand, you will need to deactivate if you have it on and remove the folder:

deactivate
rm -rf <env name>

2. Create an env. with another Python version

When you create an environment the python uses the current version by default, so if you want another one you will need to specify at the moment you are creating it. To make and env. with Python 3.7 called MyEnv just type:

python3.7 -m venv MyEnv

Now to make with Python 2.X use virtualenv instead of venv:

python2.7 -m virtualenv MyEnv

3. List all Python versions on my machine

If any of the previous lines of code didn't worked you probably don't have the specific version installed. First list all your versions with:

ls -ls /usr/bin/python*

If you didn't find it, install Python 3.7 using apt-get:

sudo apt-get install python3.7

And with yum:

sudo yum install python3

4. Best practice: upgrade you pip (weekly)

pip install --upgrade pip
8

I used pyenv uninstall my_virt_env_name to delete the virual environment.

Note: I'm using pyenv-virtualenv installed through the install script.

Ole Henrik Skogstrøm
  • 5,714
  • 10
  • 53
  • 79
7

The following command works for me.

rm -rf /path/to/virtualenv
Ashiq Imran
  • 1,224
  • 15
  • 12
6

If you are a Windows user and you are using conda to manage the environment in Anaconda prompt, you can do the following:

Make sure you deactivate the virtual environment or restart Anaconda Prompt. Use the following command to remove virtual environment:

$ conda env remove --name $MyEnvironmentName

Alternatively, you can go to the

C:\Users\USERNAME\AppData\Local\Continuum\anaconda3\envs\MYENVIRONMENTNAME

(that's the default file path) and delete the folder manually.

Shekhar
  • 101
  • 9
CathyQian
  • 718
  • 9
  • 23
1

if you are windows user, then it's in C:\Users\your_user_name\Envs. You can delete it from there.

Also try in command prompt rmvirtualenv environment name.

I tried with command prompt so it said deleted but it was still existed. So i manually delete it.

jahmed31
  • 21
  • 1
  • Actually this isn't true. The location of the virtual environment really depends on where you execute the `virtualenv` command. E.g.: `C:\>virtualenv my_awesome_venv` will create the virtual environment in `C:\my_awesome_venv`. – Felix Apr 01 '17 at 11:55
  • i was talking about the virtualwrapper. My mistake – jahmed31 Apr 01 '17 at 12:11
1

deactivate is the command you are looking for. Like what has already been said, there is no command for deleting your virtual environment. Simply deactivate it!

garrettmac
  • 7,610
  • 1
  • 36
  • 53
  • This doesn't answer the question. You are correct that you usually don't need to destroy your virtualenv, but that's what the OP seems to be asking about. – tripleee Apr 13 '19 at 14:41
1

If you're a windows user, you can also delete the environment by going to: C:/Users/username/Anaconda3/envs Here you can see a list of virtual environment and delete the one that you no longer need.

Shekhar
  • 101
  • 9
0

You can follow these steps to remove all the files associated with virtualenv and then reinstall the virtualenv again and using it

cd {python virtualenv folder}

find {broken virtualenv}/ -type l                             ## to list out all the links

deactivate                                           ## deactivate if virtualenv is active

find {broken virtualenv}/ -type l -delete                    ## to delete the broken links

virtualenv {broken virtualenv} --python=python3           ## recreate links to OS's python

workon {broken virtualenv}                       ## activate & workon the fixed virtualenv

pip3 install  ... {other packages required for the project}

Khushhalm
  • 344
  • 5
  • 10
0

Actually requires two deletions.

The project folder which everyone in this thread already said you simply delete manually or using rm -r projectfoldername

But then you also need to delete the actual virtualenv located in macOS /Users/edison/.pyenv/versions/3.8.0/envs/myspecialenv.

You can do that by doing pyenv virtualenv-delete myspecialenv or manual removal.

Edison
  • 10,891
  • 4
  • 36
  • 46
-9

step 1: delete virtualenv virtualenvwrapper by copy and paste the following command below:

$ sudo pip uninstall virtualenv virtualenvwrapper

step 2: go to .bashrc and delete all virtualenv and virtualenvwrapper

open terminal:

$ sudo nano .bashrc

scroll down and you will see the code bellow then delete it.

# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

next, source the .bashrc:

$ source ~/.bashrc

FINAL steps: without terminal/shell go to /home and find .virtualenv (I forgot the name so if your find similar to .virtualenv or .venv just delete it. That will work.

  • This appears to answer a completely different question, and should come with a huge warning. Some of the advice is also poor (sourcing your `.bashrc` again does nothing useful, and could have unwelcome consequences). – tripleee Apr 13 '19 at 14:37