How do I remove/delete a virtualenv?

前端 未结 16 986
感动是毒
感动是毒 2020-11-29 14:25

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

I cannot remove it with the following command: rmvirtualenv venv

相关标签:
16条回答
  • 2020-11-29 14:52

    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.

    0 讨论(0)
  • 2020-11-29 14:52

    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.

    0 讨论(0)
  • 2020-11-29 14:53

    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.

    0 讨论(0)
  • 2020-11-29 14:57

    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
    
    0 讨论(0)
  • 2020-11-29 14:58

    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/
    
    0 讨论(0)
  • 2020-11-29 14:59

    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
    
    0 讨论(0)
提交回复
热议问题