24
votes

I am trying to find out why my virtualenv and/or virtualenv wrapper - installed using pip using homebrew - cannot be found. I think it's because it's not added to my PATH:

$ which virtualenv
$ 

and:

$ virtualenv someDir
$ -bash: virtualenv: command not found

I installed pip using homebrew, and virtualenv using pip, without problems. I tried reinstalling virtualenv, but that did not work either. How do I know what path to add to PATH? Just the path that virtualenv.py seems to be installed into? That seems to be:

/usr/local/lib/python2.7/site-packages/virtualenv.py

I also found this guide, which suggests this:

$ ln -s ../Cellar/python/2.7/Frameworks/Python.framework/Versions/2.7/bin/virtualenv virtualenv

However, it does not help me run virtualenv. I am on Mac OSX 10.7.5 (Lion).

9
It's not a path issue. Pip puts an executable file named virtualenv in /usr/local/bin/ when successfully installed. Try pip uninstall virtualenv and then reinstall sudo pip install virtualenv. sudo because you'll need to install it in global scope. - Bibhas Debnath
@Bibhas but if i load launchd.conf, i have /usr/local/bin added to my path so then i should be able to just use virtualenv in bash right? or pip only put it there when using sudo? where could i have found this information? - Michael Trouw
@Bibhas i tried what you suggested, i did: + $ pip uninstall virtualenv + $ pip uninstall virtualenvwrapper + $ sudo pip install virtualenv + $ cd /usr/local/bin/ + $ find virtualenv + find: virtualenv: No such file or directory`` So something is going wrong here? that would make sense... but why?? - Michael Trouw
how did you install pip? which package did you install with brew? can you check the pip version with pip -V? when you install virtualenv with pip, does it give any error? can you post the install log? - Bibhas Debnath
See this screenshot d.pr/i/paQQ for the first 3 questions, and this one for installing virtualenv: d.pr/i/c4pE and virtualenvwrapper: d.pr/i/L7E0 Also, i had no errors installing virtualenv at any time, i did have warnings.. - Michael Trouw

9 Answers

16
votes

It seems that I myself am the exception to the rule for almost all 'simple' installation procedures. For some reason, it WAS a path related issue:

I ran brew info python, which outputted a lot of information. At the bottom I found this:

Executable python scripts will be put in:
/usr/local/share/python
so you may want to put "/usr/local/share/python" in your PATH, too.

I added that to my PATH in /etc/launchd.conf and ~/.bashrc and lo and behold:

$ which virtualenv 

tells me:

"/usr/local/share/python/virtualenv"

I still don't know why I couldn't find any pointers in the right direction, online, anywhere? Is pip install virtualenv supposed to add to the PATH itself? If so, why not on my system? Why did @bibhas tell me explicitly it was not a path issue?

10
votes

Had the same issue after pip install virtualenv

When I inspected python ls -la /usr/local/bin/python I found it was symbolically linked to /Library/Frameworks/Python.framework/Versions/2.7/bin/python

When I cd in that directory I also found the virtualenv executable and

Fixed it by

  1. cd /Library/Frameworks/Python.framework/Versions/2.7/bin
  2. ln virtualenv /usr/local/bin/virtualenv

Sidenote: I also happen to have a python installation in /System/Library/Frameworks/Python.framework/Versions/2.7/bin

I believe that's the one that came with OSX

2
votes

In your .bashrc you need to have:

export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
1
votes

I solved it by: At first find out it located at /usr/local/python3 and then I fix it by the command: ln virtualenv /usr/local/bin/virtualenv

0
votes

This solution will give you an alternate tool to use and solve your virtualenv problem at the same time.

Use pythonbrew. It is inspired from rvm in the ruby world and is helpful in managing pythons on your system and also wrap virtualenv commands to provide virtual environment management. I use it Mountain Lion for my development purposes and have had no problems. More details (on my blog): http://stacktoheap.com/blog/2013/03/11/why-use-virtualenv-when-there-is-pythonbrew/

0
votes

My idea is to add your virtualenv position to the BASH PATH

export PATH=$PATH:/usr/local/python2.7/bin Or change your position

0
votes

For those with Python 2.7, I came across this as well, and solved it by simply putting the following line into the \etc\paths file (may need to $ sudo chmod it first):

/Library/Frameworks/Python.framework/Versions/2.7/bin

Save the change and start a new Terminal session. Check it with echo $PATH

0
votes

(Mac / Linux specific) So I got an error message when I did a pip3 install --user --upgrade virtualenv telling me that I did not have Users/home/Library/Python/3.7/bin in my PATH. So I simply added it.

If this is on the Mac, the following did it for me

vi ~/.bash_profile



PATH="/Users/home/Library/Python/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"

restart your terminal and type virtualenv env and that should do it.

-1
votes

The module in /usr/local/lib/python2.7/site-packages is imported by a short script that uses pkg_resources.load_entry_point to run the application. The utility script should be in /usr/local/bin.