What to do when anaconda’s deactivate and virtualenvwrapper’s deactivate conflict
Over the weekend I attended a meetup on data science which was to teach us on extracting data from the genome. It was a great introduction to the topic.
One of the requirements was that we had to install anaconda, a Python and R distribution for large scale data processing. [1]
The installation process was easy enough and the talk went great. I wake up Monday morning to activate my virtualenv to find
Error: deactivate must be sourced. Run 'source deactivate'
instead of 'deactivate'.My virtual environment was active but this was disturbing. I had to investigate.
During my investigation I came to learn that: [2]
activate is an executable script in anaconda’s bin directory, but is a function in virtualenvwrapper.sh. So this is sort of a namespace collision problem, but also a case of overlap in functionality.
To solve this: [3]
So, in the
virtualenvwrapper.shscript, we can change the following two lines which test for whetherdeactivateis merely callable:
type deactivate >/dev/null 2>&1
if [ $? -eq 0 ]with the stricter test for whether it’s a shell function:
nametype="$(type -t deactivate)"
if [ "${nametype##* }" == "function" ]This change avoids triggering the spurious error noted in the original question, but doesn’t risk redirecting other useful errors or output into silent oblivion.
If you installed virtualenvwrapper using pip, you should find it in the directory
$ cd /usr/local/binIf your installation is similar to mine, you should find it in the directory
$ cd ~/.local/binIf you use vim as your editor open the file
$ vim virtualenvwrapper.shWhile still in the normal mode [4], type
:? type deactivateThis will take you directly to the lines you intend to change
type deactivate >/dev/null 2>&1
if [ $? -eq 0 ]You can delete them or comment them out and add the following two lines
nametype="$(type -t deactivate)"
if [ "${nametype##* }" == "function" ]Exit the script and source the file for your changes to take effect.
:wqThen
source virtualenvwrapper.shThat’s all folks.
[1] — https://stackoverflow.com/a/42096429, https://en.wikipedia.org/wiki/Anaconda_(Python_distribution)
[2] — https://stackoverflow.com/a/38198815
[3] — https://stackoverflow.com/a/42014049
[4] — https://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim/Modes
