3
votes

I'm trying to install opencv using python2.7.

When I use brew install python. I got

Warning: python-2.7.11 already installed, it's just not linked

And then I run brew link python and brew install python again got

1 export PATH="/usr/local/mysql/bin:$PATH"

Warning: python-2.7.11 already installed

But which python still told me I'm using /usr/bin/python.

I changed my ~/.bash_profile to

  1 export PATH="/usr/local/mysql/bin:$PATH"
  2  #Setting PATH for Python 3.5
  3 # The orginal version is saved in .bash_profile.pysave
  4 PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
  5 export PATH
  6 # Homebrew
  7 export PATH="/usr/local/bin:$PATH"

No thing happens. It seems that I should be using /usr/local/bin/python because opencv is installed by homebrew.

How to solve this?

3

3 Answers

4
votes

Did you try closing your terminal session and then open a new one? ~/.bash_profile is only picked up when bash is executed as a login shell, which is the default for Terminal.app when you open a new terminal window. Or you can do source ~/.bash_profile if you do not want to close the terminal session for some reason.

Side note: You might want to add the following at the top of your ~/.bash_profile:

if [ -f ~/.bashrc ]; then
        source ~/.bashrc
fi

So that your ~/.bashrc is also executed. Optionally you can also add:

if [ -f `brew --prefix`/etc/bash_completion ]; then
    source `brew --prefix`/etc/bash_completion
fi

To enable bash completion for brew commands.

0
votes

Recent versions of Homebrew and OSX have switched from putting python in /usr/local/bin to /usr/local/opt/python/libexec/bin

You want to do something like:

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

To get the homebrew python.

0
votes

I changed it to /usr/local/bin like following:

export PATH="/usr/local/python/libexec/bin:$PATH"

Works perfectly for me. That's what I want to use.