Homebrew link python to /usr/local/bin/ on Mac

Viewed 9230

I would like to ask how to install python on Mac through Homebrew. Homebrew is a package manager for Mac.

Specifically I would like to link python to /usr/local/bin/ and not to /usr/bin/ where it is linked by default.

The reason to do this is that I want then to install a virtual environment which will provide me the libraries of python (see: https://www.learnopencv.com/install-opencv3-on-macos/). Otherwise the virtual environment cannot be installed as source /usr/local/bin/virtualenvwrapper.sh in the bash_profile cannot be read.

Do you have any idea how can I do this?

In brief, I want the output to which python at terminal to be /usr/local/bin/python and not /usr/bin/python as it is by default.

UPDATE: I applied the changes that TomD described below (I hope correctly!) but now which python has not output: is not /usr/local/bin/python as I would like (not even /usr/bin/python). So why finally python from 'cellar' is not linked to /usr/local/bin/python?

1 Answers

Just to give a few basics first. Homebrew installs everything in the "cellar". That's where the "kegs" (packages) go.

Homebrew then creates symlinks to their files into /usr/local/.

For example, python is installed in /usr/local/Cellar/python

So I would suggest after installation, remove the symlink to /usr/bin and make one to /usr/local/bin.

remove symlink:

unlink /usr/bin/python

make symlink:

ln -s /usr/local/Cellar/python /usr/bin/python

also make sure that your $PATH is correct and /usr/local/bin is before usr/bin

Related