Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python - Change python to /usr/local/bin/python?

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?

like image 351
jinglei Avatar asked Jun 01 '26 19:06

jinglei


1 Answers

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.

like image 52
n.abing Avatar answered Jun 03 '26 09:06

n.abing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!