Question

I've run into a very strange problem with virtualenv and virtualenvwrapper that has me stumped. I develop Django/Python applications on a MacBook Air running OS X 10.8.5. Yesterday, out of the blue, when I started opening new iTerm console windows, I'd get these two messages:

-bash: GREP_OPTIONS: command not found
-bash: GREP_OPTIONS: command not found

I narrowed the source of the error to this line in my .bash_profile:

source /usr/local/bin/virtualenvwrapper.sh

I don't use any GREP_OPTIONS environment variable in any of my "dot" files. When I run the above source command manually, I get the same two errors.

After making a backup copy of virtualenvwrapper.sh, I added "set -xv" at the top and re-ran it and discovered that the line generating the first error message is this "if" line in the "function virtualenvwrapper_derive_workon_home" function:

 if echo "$workon_home_dir" | (unset GREP_OPTIONS; command \grep '^[^/~]' > /dev/null)
then
    workon_home_dir="$HOME/$WORKON_HOME"
fi

I saw that $workon_home_dir was set correctly to my virtual environment directory "/Users/[myname]/.virtualenvs".

Here are the pertinent lines in my .bash_profile file:

# .bash_profile
...
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi
...
# I do set the path before running virtualenvwrapper.sh
export PATH=/usr/local/pgsql/bin:$PATH
...
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
...

After reading the virtualenvwrapper installation instructions, I tried adding these two lines above the source line to no avail:

# Path to my global python executable
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
# Path to virtualenv executable
export VIRTUALENWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv

Now when I enter the "workon" command, I see a list of my virtual environments as expected. However, if I try to activate one of them, e.g. my "python" venv by doing, "workon python", I see this!!

$ workon python
pydoc - the Python documentation tool

pydoc <name> ...
    Show test documentation...
    (... other lines of documentation ...)

If I then enter the deactivate command, I'll see the same pydoc lines as above plus some extra messages like these:

-bash: _OLD_VIRTUAL_PATH: command not found
-bash: _OLD_VIRTUAL_PS1: command not found
-bash: VIRTUAL_ENV: command not found
-bash: -f: command not found
-bash: VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV: command not found

I tried de-installing and re-installing virtualenv and virtualenvwrapper using pip but that didn't fix the problem.

To make things even weirder, I noticed something else. I put all my Django projects into a Dropbox directory ~/www. A day or two ago I noticed that all of my Django projects that were in this directory and that started with the letter "a" through "h" have disappeared. I don't remember entering any commnands that could have selectively deleted these project directories.

This almost feels like perhaps my disk has developed some bad sectors which have corrupted one or more of my virtualenvwrapper files. Does anyone have any idea what might be causing these problems?

Thanks.

Was it helpful?

Solution

I did two things to resolve this problem. First, I upgraded my OS to OS X 10.9 and did a clean install. This seemed like a problem that was in the guts of my machine and I didn't know how to fix it. But even after doing a clean re-install, I continued to see the Pydoc documentation when running the workon command. I finally narrowed the problem down to this one alias I had in my .bashrc file:

alias unset="DJANGO_SETTINGS_MODULE="

I had created this convenience alias because there were times when this environment variable would contain an old value and I wanted a way to reset it easily. I still don't understand why this caused the problem. If I named the alias anything other than "unset", the problem would go away.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top