Pip packages not found - Brewed Python

11,268

The problem was that I had not added Python to the system $PATH.

At the end of the brew install it says (viewable by typing brew info python):

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.

So, simply had to open .profile and paste it in, and all packages work.

Much thanks to MistyM on the Brew IRC channel for pointing that out!

Share:
11,268
SamGoody
Author by

SamGoody

Updated on June 14, 2022

Comments

  • SamGoody
    SamGoody almost 2 years

    Running Python 2.7.3, installed with HomeBrew, on a mac.

    Installed several packages using PIP, including virtualenv. (Using virtualenv as an example, but NONE of the packages work.)

    When I try to run them in terminal, it fails as follows:

    $ virtualenv venv --distribute
    -bash: virtualenv: command not found
    

    Alternatively:

    $ python virtualenv.py venv
    /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'virtualenv.py': [Errno 2] No such file or directory
    

    A few other points that may help:

    $ which python
    /usr/local/bin/python
    $ pip freeze
    MySQL-python==1.2.4
    ...
    virtualenv==1.8.4
    $ echo $PATH
    /usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
    $ echo $PYTHONPATH
    /usr/local/lib/python2.7/site-packages:
    

    By default, the $PYTHONPATH was blank, I changed it in .bash_profile (didn't help). VirtualEnv does exist at that path. I also tried adding this path to the .profile $path, but that didn't help either, so I removed it.

    On the HomeBrew Python page it seems to somewhat relate to this, but I am new to Python, and can't figure it out. Have spent some hours DuckDuckGo'ing with nothing gained.

    Any help would be greatly appreciated.

    EDIT: Updated to reflect actual usage.

  • SamGoody
    SamGoody over 11 years
    $ mkdir awesomeapp; $ cd awesomeapp; $ virtualenv venv --distribute; -bash: virtualenv: command not found; I get the same error as before.
  • SamGoody
    SamGoody over 11 years
    I'm not sure I understand - In your example above is YOURVIRTUALSERVER the one you referred to as venv? When I run the first line it errs out: $ python virtualenv.py venv; /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/V‌​ersions/2.7/Resource‌​s/Python.app/Content‌​s/MacOS/Python: can't open file 'virtualenv.py': [Errno 2] No such file or directory The ; represents a line break - I dont know how to put line breaks in comments on SO
  • Mikko Ohtamaa
    Mikko Ohtamaa over 11 years
    So first you need to download virtualenv.py from here raw.github.com/pypa/virtualenv/master/virtualenv.py if "virtualenv" command cannot be installed on your system otherwise. The command to download on OSX from command line is above.
  • Mikko Ohtamaa
    Mikko Ohtamaa over 11 years
    I also clarified other parts of the example
  • SamGoody
    SamGoody over 11 years
    Thank you, but 1) Virtualenv is installed as demonstrated by the freeze command, and 2) There are several other PIP libraries I need as well, and all are installed but not accessible. Even if I found a solution for only VirtualEnv, it wouldn't help me that much
  • Mikko Ohtamaa
    Mikko Ohtamaa over 11 years
    But is virtualenv activated after freeze or do you need to separately activate it?
  • SamGoody
    SamGoody over 11 years
    I need to separately activate it. I was able to install it from the link you posted, but the other PIP packages were no go.
  • Mikko Ohtamaa
    Mikko Ohtamaa over 11 years
    How about this 1) Create empty virtualenv 2) run pip after virtualenv is activated. It should use virtualenvized pip.
  • ReThink
    ReThink about 11 years
    Spot on! This was a big help. Thank you so much.
  • adriendenat
    adriendenat about 11 years
    Or add it to your .bash_profile if you don't have any .profile
  • ExperimentsWithCode
    ExperimentsWithCode over 10 years
    Can you elaborate on how you add the path to your .bash_profile
  • Pih
    Pih almost 10 years
    Your solutions does not do anything related with his error.
  • topherjaynes
    topherjaynes over 9 years
    @pih before the OP changed the question it was more relevant, but thanks for point out.
  • SamGoody
    SamGoody almost 9 years
    .bash_profile is a file that is checked by Bash upon startup for (among other things) changes to the $PATH. By default, it does not exist, so you will likely have to create it, by opening the terminal and typing: touch ~/.bash_profile and pressing enter. This means "create the file in my local home directory". (Note: You won't see it in finder as it's hidden, since the name starts with a dot.) You can edit that file by typing in terminal: open ~/.bash_profile which will open the file for editing in your default program, which is probably TextEdit. If you get a blank page, it's a good sign.
  • SamGoody
    SamGoody almost 9 years
    Once you have .bash_profile open, add the following line and press save: export PATH="/usr/local/share/python:$PATH". This rewrites path to include the path to Python, which is what you need. Be aware though that in Mac, Bash also checks for .profile and .bashrc on the local user level. On the global level, it checks /etc/profile, /etc/bashrc and /etc/bash_profile [and probably many others].
  • SamGoody
    SamGoody almost 9 years
    On second thought, it seems that bash also checks the global /etc/paths. So ignore what I wrote in the other comments, the easiest way to add brewed Python to PATH on a global level, assuming you have sudo privileges, is sudo open /etc/paths (if it doesn't exist, create it using touch as in last comment) and adding /usr/local/share/python on it's own line. You have to close and reopen terminal for changes to take affect.