It's not currently possible, but I believe it is possible in principle if the various Python formulae were fixed up to support this.

Dealing with the various executables (python3, pip3, etc) is fairly straightforward, but there are some conflicts that will require a bit more work:

❯ brew link --force --dry-run --overwrite python@3.10
Would remove:
/usr/local/bin/2to3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/2to3
/usr/local/bin/idle3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/idle3
/usr/local/bin/pip3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/pip3
/usr/local/bin/pydoc3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/pydoc3
/usr/local/bin/python3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/python3
/usr/local/bin/python3-config -> /usr/local/Cellar/python@3.9/3.9.9/bin/python3-config
/usr/local/bin/wheel3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/wheel3
/usr/local/share/man/man1/python3.1 -> /usr/local/Cellar/python@3.9/3.9.9/share/man/man1/python3.1
/usr/local/lib/pkgconfig/python3-embed.pc -> /usr/local/Cellar/python@3.9/3.9.9/lib/pkgconfig/python3-embed.pc
/usr/local/lib/pkgconfig/python3.pc -> /usr/local/Cellar/python@3.9/3.9.9/lib/pkgconfig/python3.pc
/usr/local/Frameworks/Python.framework/Headers -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Headers
/usr/local/Frameworks/Python.framework/Python -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Python
/usr/local/Frameworks/Python.framework/Resources -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Resources
/usr/local/Frameworks/Python.framework/Versions/Current -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/Current

This might require special handling of the contents of *.framework directories in brew.

🌐
GitHub
github.com › orgs › Homebrew › discussions › 3696
Symlink not being created for my Python install · Homebrew · Discussion #3696
September 27, 2022 - /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/sirromey/opt/homebrew/opt/python@3.10/libexec/bin · looks wrong. It seems like the last entry should be ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... Ohh.. my bad. I add the ~ and it routed it to the user I think. It works fine now. Thanks a lot. If possible, it would be best if brew could do it automatically while installing.
Top answer
1 of 1
1

It's not currently possible, but I believe it is possible in principle if the various Python formulae were fixed up to support this.

Dealing with the various executables (python3, pip3, etc) is fairly straightforward, but there are some conflicts that will require a bit more work:

❯ brew link --force --dry-run --overwrite python@3.10
Would remove:
/usr/local/bin/2to3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/2to3
/usr/local/bin/idle3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/idle3
/usr/local/bin/pip3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/pip3
/usr/local/bin/pydoc3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/pydoc3
/usr/local/bin/python3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/python3
/usr/local/bin/python3-config -> /usr/local/Cellar/python@3.9/3.9.9/bin/python3-config
/usr/local/bin/wheel3 -> /usr/local/Cellar/python@3.9/3.9.9/bin/wheel3
/usr/local/share/man/man1/python3.1 -> /usr/local/Cellar/python@3.9/3.9.9/share/man/man1/python3.1
/usr/local/lib/pkgconfig/python3-embed.pc -> /usr/local/Cellar/python@3.9/3.9.9/lib/pkgconfig/python3-embed.pc
/usr/local/lib/pkgconfig/python3.pc -> /usr/local/Cellar/python@3.9/3.9.9/lib/pkgconfig/python3.pc
/usr/local/Frameworks/Python.framework/Headers -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Headers
/usr/local/Frameworks/Python.framework/Python -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Python
/usr/local/Frameworks/Python.framework/Resources -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Resources
/usr/local/Frameworks/Python.framework/Versions/Current -> /usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/Current

This might require special handling of the contents of *.framework directories in brew.

Discussions

python formula does not link to /usr/local/bin/python
After a recent brew upgrade, the Python virtualenvwrapper.sh started giving errors. It said python cannot find virtualenvwrapper module. I was trying to fix this error message. Then I did a bit debugging and realized it started using the macOS system python (/usr/bin/python) after a while. No matter how many times I reinstalled python formula, I still did not get a /usr/local/bin/python symlink... More on github.com
🌐 github.com
5
July 30, 2017
Python3: Unversioned symlinks are installed to directory not in PATH
Please note we will close your issue without comment if you delete, do not read or do not fill out the issue checklist below and provide ALL the requested information. If you repeatedly fail to use the issue template, we will block you f... More on github.com
🌐 github.com
3
April 26, 2018
Python: does not create symlink to pip
if brew gist-logs didn't work: ran brew config and brew doctor and included their output with your issue? Homebrew Does not create symlink to pip3 when I install python. When I installed python3 a few month ago, homebrew create pip3 symlink on /usr/local/bin. More on github.com
🌐 github.com
1
May 27, 2018
Python symlink shenananigans, guest starring pyEnv and Homebrew.
My advice is to never, ever, use the Hombrew Python for anything—that version of Python is strictly for other Homebrew formulae to use. The reason for this is that one day you’re going to run brew upgrade on some formula that depends on Python and if it upgrades Python in the process it will wreck your environment. So you should definitely use pyenv to manage your Python version but really you should avoid installing any Python packages there too. Why? Unlike some other programming languages you can only install ONE version of a package at a time. So if you have one project that needs sometool==1.0.0 and another project that needs sometool==2.0.0 you’re going to have problems. Instead, keep your pyenv environment as clean as possible and use a virtualized environment per project with Pipenv (my preference and maintained by the Python package authority) or Poetry (the community favorite). More on reddit.com
🌐 r/MacOS
3
9
May 12, 2022
🌐
GitHub
github.com › Homebrew › homebrew-core › issues › 16212
python formula does not link to /usr/local/bin/python · Issue #16212 · Homebrew/homebrew-core
July 30, 2017 - To have a symlink at /usr/local/bin/python after installing python formula so that it replaces my system Python.
Author: Homebrew
🌐
GitHub
github.com › Homebrew › discussions › discussions › 3696
Symlink not being created for my Python install · Discussion #3696 · Homebrew/discussions
September 27, 2022 - /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/sirromey/opt/homebrew/opt/python@3.10/libexec/bin · looks wrong. It seems like the last entry should be ... Beta Was this translation helpful? Give feedback. ... Something went wrong. ... Ohh.. my bad. I add the ~ and it routed it to the user I think. It works fine now. Thanks a lot. If possible, it would be best if brew could do it automatically while installing.
Author: Homebrew
🌐
Michael Currin
michaelcurrin.github.io › dev-cheatsheets › cheatsheets › python › install › install-and-upgrade.html
Install and upgrade Python | Dev Cheatsheets
pointing to `python3`, `python3-config`, `pip3` etc., respectively, have been installed into /usr/local/opt/python@3.9/libexec/bin You can install Python packages with pip3 install <package> They will install into the site-package directory /usr/local/lib/python3.9/site-packages See: https://docs.brew.sh/Homebrew-and-Python python@3.9 is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula.
🌐
Readthedocs
python-guide-fil.readthedocs.io › en › latest › starting › install3 › osx.html
Installing Python 3 on Mac OS X — The Hitchhiker's Guide to Python
$ python --version Python 2.7.10 # Referencing OSX system install $ which python /usr/bin/python # Yup, homebrew's would be in /usr/local/bin # Symlink /usr/local/bin/python to python3 $ ln -s /usr/local/bin/python3 /usr/local/bin/python $ python --version Python 3.6.4 # Success!
🌐
GitHub
github.com › Homebrew › homebrew-core › issues › 27140
Python3: Unversioned symlinks are installed to directory not in PATH · Issue #27140 · Homebrew/homebrew-core
April 26, 2018 - if brew gist-logs didn't work: ran brew config and brew doctor and included their output with your issue? ... What happened (include command output) Installed but links python → python3, pip → pip3 etc.
Author: Homebrew
Find elsewhere
🌐
GitHub
github.com › Homebrew › homebrew-core › issues › 28335
Python: does not create symlink to pip · Issue #28335 · Homebrew/homebrew-core
May 27, 2018 - if brew gist-logs didn't work: ran brew config and brew doctor and included their output with your issue? Homebrew Does not create symlink to pip3 when I install python. When I installed python3 a few month ago, homebrew create pip3 symlink on /usr/local/bin.
Author: Homebrew
🌐
Reddit
reddit.com › r/macos › python symlink shenananigans, guest starring pyenv and homebrew.
r/MacOS on Reddit: Python symlink shenananigans, guest starring pyEnv and Homebrew.
May 12, 2022 -

I have very recently discovered pyEnv and used that to set my default python system install on Monterey 12.3.1 to the latest version of Python (3.10.4 as of yesterday). Installed and configured, and all is good.

Prior to discovering pyEnv, I have python installed via Homebrew.

The latest version of Python I can have installed via Homebrew ( brew upgrade python ) is 3.9.12 and I have many packages symlinked to this version. Removing this install of python ( brew uninstall --ignore-dependencies python ) breaks all of these packages, obviously.

Rather than having two distinct versions of Python installed, is there a reasonably simple way to divert all my Homebrew package symlinks to the 3.10.4 pyEnv environment so that I can then remove the 3.9.12 enviroment from Homebrew.

I'm not afraid of the command line, but symlinks hurt my brain. :) Would the 'brew link' command be my friend?

Top answer
1 of 7
84

brew install python or brew info python output mentions:

Unversioned symlinks python, python-config, pip etc. pointing to python3, python3-config, pip3 etc., respectively, have been installed into /opt/homebrew/opt/[email protected]/libexec/bin

So running, as root (for Bash (executable bash), use the ~/.bash_profile file):

echo 'export PATH=/opt/homebrew/opt/[email protected]/libexec/bin:$PATH' >> ~/.zprofile
source ~/.zprofile

gets you those symlinks created by Homebrew, python=python3, pip=pip3, etc.

python --version

Output:

Python 3.9.10

And:

pip --version

Output:

pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
2 of 7
38

If you want to install Python 3 using Homebrew:

brew install python3

Output:

==> Downloading http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
Already downloaded: /Library/Caches/Homebrew/python3-3.3.0.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/python3/3.3.0 --enable-ipv6 --datarootdir=/usr/local/Cell
==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python3/3.3.0
==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python3/3.3.0/share/python3
==> Downloading https://pypi.python.org/packages/source/d/distribute/distribute-0.6.35.tar.gz
Already downloaded: /Library/Caches/Homebrew/distribute-0.6.35.tar.gz
==> /usr/local/Cellar/python3/3.3.0/bin/python3.3 -s setup.py install --force --verbose --install-li
==> Downloading https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/pip-1.3.1.tar.gz
==> /usr/local/Cellar/python3/3.3.0/bin/python3.3 -s setup.py install --force --verbose --install-li
==> Caveats
Homebrew's Python3 framework
  /usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework

Distribute and Pip have been installed. To update them
  pip3 install --upgrade distribute
  pip3 install --upgrade pip

To symlink "Idle 3" and the "Python Launcher 3" to ~/Applications
  `brew linkapps`

You can install Python packages with
  `pip3 install <your_favorite_package>`

They will install into the site-package directory
 /usr/local/lib/python3.3/site-packages
Executable python scripts will be put in:
 /usr/local/share/python3
so you may want to put "/usr/local/share/python3" in your PATH, too.

    See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python

Once installed update your system PATH variable, add the next line to the ~/.bash_profile file:

export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH

And then:

source ~/.bash_profile

Now launch Python:

python3

Output:

Python 3.3.0 (default, Mar 26 2013, 10:01:40)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

You can check the python3 path:

which python3

Output:

/usr/local/bin/python3
🌐
GitHub
github.com › Homebrew › homebrew-core › issues › 24792
installing python3 symlinked incompatible "python" binary · Issue #24792 · Homebrew/homebrew-core
March 3, 2018 - Homebrew then created a python ... to symlink, or it installs the conflicting packages under a different name. ... $ brew install llvm ......
Author: Homebrew
🌐
GitHub
github.com › Homebrew › legacy-homebrew › issues › 16320
Python 3 symlink error when Python 2.7 installed. · Issue #16320 · Homebrew/legacy-homebrew
November 30, 2012 - Usually I could do 'brew install python python3' and I would get two separate python versions. Now, after the installation of python I get a symlink error with python3 saying: Error: Could not symlink file: /usr/local/Cellar/python3/3.3....
Author: Homebrew
🌐
Homebrew
formulae.brew.sh › formula › symlinks
Homebrew Formulae: symlinks
brew install symlinks · Symbolic link maintenance utility · https://github.com/brandt/symlinks · License: MIT · Development: Pull requests · Formula JSON API: /api/formula/symlinks.json · Formula code: symlinks.rb on GitHub · Bottle (binary package) installation support provided for: Current versions: Binaries: symlinks ·
🌐
Stack Overflow
stackoverflow.com › questions › 17409445 › brew-install-python-unable-couldnt-symlink-file
installation - Brew Install Python - Unable Couldn't symlink file: - Stack Overflow
May 27, 2016 - To update them pip install --upgrade distribute pip install --upgrade pip To symlink "Idle" and the "Python Launcher" to ~/Applications `brew linkapps` You can install Python packages with (the outdated easy_install or) `pip install ...
🌐
GitHub
github.com › orgs › Homebrew › discussions › 3596
Why not reference python3 as just python too when installed from brew? · Homebrew · Discussion #3596
@MikeMcQuaid thanks, I made a PR to change the unversioned symlink note on https://docs.brew.sh/Homebrew-and-Python#python-3y since (at least with a typical setup with bash and .bash_profile) you get a visible error message when opening a shell if the package is not installed which is really ...
🌐
GitHub
github.com › actions › runner-images › issues › 8529
homebrew Python link failure causes all macOS runner actions to fail · Issue #8529 · actions/runner-images
October 11, 2023 - You may want to remove it: rm ... ... tkinter is no longer included with this formula, but it is available separately: brew install ......
Author: actions