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.
python formula does not link to /usr/local/bin/python
Python3: Unversioned symlinks are installed to directory not in PATH
Python: does not create symlink to pip
Python symlink shenananigans, guest starring pyEnv and Homebrew.
After installing python3 with brew install python3
I was getting the error:
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
After typing brew link python3 the error was:
Linking /usr/local/Cellar/python/3.6.4_3... Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
To solve the problem:
sudo mkdir -p /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/*
brew link python3
After this, I could open python3 by typing python3 👍
(From https://github.com/Homebrew/homebrew-core/issues/20985)
In the Terminal, type:
brew link python
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?
brew install python or brew info python output mentions:
Unversioned symlinks
python,python-config,pipetc. pointing topython3,python3-config,pip3etc., 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)
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
Probably the safest and easy way is to use brew and then just modify your PATH:
First update brew:
brew update
Next install python:
brew install python
That will install and symlink python3 to python, for more details do:
brew info python
Look for the Caveats:
==> Caveats
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
Then add to your path /usr/local/opt/python/libexec/bin:
export PATH=/usr/local/opt/python/libexec/bin:$PATH
The order of the PATH is important, by putting first the /usr/local/opt/python/libexec/bin will help to give preference to the brew install (python3) than the one is in your system located in /usr/bin/python
Before we make the changes, the default version of python in my system was python 2.7.17.
python --versionPython 2.7.17
To make python3 as default python by replacing python2 in Ubuntu.
- Open Terminal
cdnano ~/.bashrcalias python=python3(Add this line on top of .bashrc file)- Press
ctr+o(To save the file) - Press
Enter - Press
ctr+x(To exit the file) source ~/.bashrcOR. ~/.bashrc(To refresh the bashrc file)
python --versionPython 3.7.5