1

I need to install virtualenvwrapper on my macOS Sierra to be able to install TensorFlow. Previously I had installed Python 3 based on the instructions here using Homebrew.

Now pip seemed to be nonexistent (pip2 and pip3 worked though), so I did

sudo easy_install pip

Then I followed the instructions given here, and when I do

source /usr/local/bin/virtualenvwrapper.sh

I get the following error:

No module named virtualenvwrapper virtualenvwrapper.sh:
There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is set properly.

I have tried the solutions given here, and here, but no success. I have even tried to install virtualenvwrapper with:

sudo pip2 install --upgrade virtualenvwrapper

and

sudo pip3 install --upgrade virtualenvwrapper

and still I get the same error. Could someone please help me with this issue?

EDIT:

I have tried to do lazy loading of the virtualenvwrapper like so:

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
source /usr/local/bin/virtualenvwrapper_lazy.sh

Only then I don't get any errors, and I am able to proceed with installing TensorFlow. But then every time I open a new terminal workon does not work, and I have to do source /usr/local/bin/virtualenvwrapper_lazy.sh every time to be able to use workon. Even when workon is invoked I get a warning/error message as /usr/bin/python: No module named virtualenvwrapper.

Could someone help me see what is going on here?

user20112015
  • 307
  • 1
  • 3
  • 9

1 Answers1

2

My solution is simply a hack and not a clean and logical way for solving this but you could edit /usr/local/bin/virtualenvwrapper.sh as root and in the section that is followed by

# Locate the global Python where virtualenvwrapper is installed.

remove the if/else condition and simply use VIRTUALENVWRAPPER_PYTHON="$(command \which python3.5)" (Change 3.5 to your version) and then source the file again.

Amin Etesamian
  • 3,363
  • 5
  • 27
  • 50
  • Thanks for your reply. But now I get the following error `-bash: /usr/local/bin/virtualenvwrapper.sh: line 127: syntax error near unexpected token` ``os.path.normpath'` `-bash: /usr/local/bin/virtualenvwrapper.sh: line 127: ` `"$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.normpath(os.path.expanduser(os.path.expandvars(\"$1\")))+'\n')"'` – user20112015 Aug 13 '17 at 10:19
  • You have a typo! copy and paste line 127 of the file here – Amin Etesamian Aug 13 '17 at 10:44
  • I don't think I have a typo. Even replacing the if/else with just `VIRTUALENVWRAPPER_PYTHON="$(command \which python)"` still gives the old initalization of hooks error. :-/ – user20112015 Aug 13 '17 at 11:12
  • do you use python3.5? – Amin Etesamian Aug 13 '17 at 11:15
  • I have installed python2.7 and 3.6 with brew. – user20112015 Aug 13 '17 at 11:18
  • I still get the same error -bash: /usr/local/bin/virtualenvwrapper.sh: line 123: syntax error near unexpected token `os.path.normpath' -bash: /usr/local/bin/virtualenvwrapper.sh: line 123: ` "$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.normpath(os.path.expanduser(os.path.expandvars(\"$1\")))+'\n')"' – user20112015 Aug 13 '17 at 11:31
  • By the way doing `which python` yields `/usr/bin/python` which I think is the apple's default install of python? – user20112015 Aug 13 '17 at 11:37
  • copy and paste the next lines of `# Locate the global Python where virtualenvwrapper is installed.` here – Amin Etesamian Aug 13 '17 at 11:42
  • `# Locate the global Python where virtualenvwrapper is installed. VIRTUALENVWRAPPER_PYTHON="$(command \which python3.6)” # Set the name of the virtualenv app to use. if [ "$VIRTUALENVWRAPPER_VIRTUALENV" = "" ] then VIRTUALENVWRAPPER_VIRTUALENV="virtualenv" fi` – user20112015 Aug 13 '17 at 11:56
  • Ops! notice the `”` after `python3.6)` it should be double quotes (`"`). use `VIRTUALENVWRAPPER_PYTHON="$(command \which python3.6)"` instead – Amin Etesamian Aug 13 '17 at 13:45
  • Thank you so much this solved the problem! However, when I open a new terminal and I type `workon` it says `workon: command not found`. Why is that? – user20112015 Aug 13 '17 at 14:09
  • you have to put the source command in your bashrc file. `'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bash_profile` – Amin Etesamian Aug 13 '17 at 14:27
  • http://exponential.io/blog/2015/02/10/install-virtualenv-and-virtualenvwrapper-on-mac-os-x/ – Amin Etesamian Aug 13 '17 at 14:28
  • 1
    Awesome! Thank you so much! You are a star! :) – user20112015 Aug 13 '17 at 14:41