The Python Oracle

How to leave/exit/deactivate a Python virtualenv

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC G Dvoks String Quartet No 12 Ame 2

--

Chapters
00:00 Question
00:46 Accepted answer (Score 3766)
01:41 Answer 2 (Score 114)
02:10 Answer 3 (Score 64)
02:30 Answer 4 (Score 36)
02:47 Thank you

--

Full question
https://stackoverflow.com/questions/9907...

Accepted answer links:
[Anaconda]: https://en.wikipedia.org/wiki/Anaconda_(...)

Answer 2 links:
[Bash ]: https://superuser.com/a/46146/3376

Answer 3 links:
[alias]: https://askubuntu.com/questions/17536/ho...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #virtualenv #exit #virtualenvwrapper

#avk47



ACCEPTED ANSWER

Score 4209


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



ANSWER 2

Score 159


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.




ANSWER 3

Score 69


I defined an alias, workoff, as the opposite of workon:

alias workoff='deactivate'

It is easy to remember:

[bobstein@host ~]$ workon django_project
(django_project)[bobstein@host ~]$ workoff
[bobstein@host ~]$



ANSWER 4

Score 46


To activate a Python virtual environment:

$cd ~/python-venv/
$./bin/activate

To deactivate:

$deactivate