Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 workon command.

me@mymachine:~$ workon env1 (env1)me@mymachine:~$ workon env2 (env2)me@mymachine:~$ workon env1 (env1)me@mymachine:~$  

How do I exit all virtual environments and work on my system environment again? Right now, the only way I have of getting back to me@mymachine:~$ 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?

like image 266
Apreche Avatar asked Jun 13 '09 14:06

Apreche


People also ask

How do I get out of python virtualenv?

You can exit from the virtualenv using exit command, or by pressing Ctrl+d.

How do you exit Conda in Python?

To exit the virtual environment, use the command conda deactivate . If you run conda info --envs again, there is no * in front of env_name .

How do I know if my virtual environment is activated?

Check the $VIRTUAL_ENV environment variable. The $VIRTUAL_ENV environment variable contains the virtual environment's directory when in an active virtual environment. Once you run deactivate / leave the virtual environment, the $VIRTUAL_ENV variable will be cleared/empty.


2 Answers

Usually, activating a virtualenv gives you a shell function named:

$ deactivate 

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:

conda deactivate 

Older conda versions instead implement deactivation using a stand-alone script:

source deactivate 
like image 159
Brandon Rhodes Avatar answered Oct 07 '22 08:10

Brandon Rhodes


Use:

$ deactivate  

If this doesn't work, try

$ source deactivate 

Anyone who knows how Bash source works will think that's odd, but some wrappers/workflows around virtualenv implement it as a complement/counterpart to source activate. Your mileage may vary.

like image 36
DarkRider Avatar answered Oct 07 '22 08:10

DarkRider