[python-3.x] How do I remove/delete a virtualenv?

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.

The answer is


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.


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!


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

I used pyenv uninstall my_virt_env_name to delete the virual environment.

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


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/

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

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.


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


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

rm -rf venv

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

$ pyenv virtualenv-delete <name>

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}


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.


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.


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.


The following command works for me.

rm -rf /path/to/virtualenv

Examples related to python-3.x

Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation Replace specific text with a redacted version using Python Upgrade to python 3.8 using conda "Permission Denied" trying to run Python on Windows 10 Python: 'ModuleNotFoundError' when trying to import module from imported package What is the meaning of "Failed building wheel for X" in pip install? How to downgrade python from 3.7 to 3.6 I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? Iterating over arrays in Python 3 How to upgrade Python version to 3.7?

Examples related to virtualenvwrapper

What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc? virtualenvwrapper and Python 3 bash: mkvirtualenv: command not found Where is virtualenvwrapper.sh after pip install? How do I remove/delete a virtualenv? List all virtualenv How to use MySQLdb with Python and Django in OSX 10.6? Use different Python version with virtualenv How to leave/exit/deactivate a Python virtualenv

Examples related to python-venv

What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc? How do I remove/delete a virtualenv?

Examples related to virtual-environment

How do I remove/delete a virtualenv?

Examples related to virtualenv-commands

How do I remove/delete a virtualenv? List all virtualenv