How to leave/exit/deactivate a Python virtualenv
I'm using virtualenv and the virtualenvwrapper. I can switch between virtualenv's just fine using the
[email protected]:~$ workon env1 (env1)[email protected]:~$ workon env2 (env2)[email protected]:~$ workon env1 (env1)[email protected]:~$
How do I exit all virtual machines and work on my real machine again? Right now, the only way I have of getting back to
[email protected]:~$ is to exit the shell and start a new one. That's kind of annoying. Is there a command to work on "nothing", and if so, what is it? If such a command does not exist, how would I go about creating it?
Usually, activating a virtualenv gives you a shell function named:
which puts things back to normal.
I have just looked specifically again at the code for
virtualenvwrapper, and, yes, it too supports
deactivate as the way to escape from all virtualenvs.
If you are trying to leave an Anaconda environment, the command depends upon your version of
conda. Recent versions (like 4.6) install a
conda function directly in your shell, in which case you run:
Older conda versions instead implement deactivation using a stand-alone script:
Read more... Read less...
To activate a Python virtual environment:
$cd ~/python-venv/ $./bin/activate
I found that when within a Miniconda3 environment I had to run:
source deactivate worked for me.
You can use
virtualenvwrapper in order to ease the way you work with
pip install virtualenvwrapper
If you are using a standard shell, open your
~/.zshrc if you use Oh My Zsh. Add these two lines:
export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh
To activate an existing virtualenv, use command
$ workon myenv (myenv)$
In order to deactivate your virtualenv:
Here is my tutorial, step by step on how to install virtualenv and virtualenvwrapper.