Skip to content

Pre-installed Python conflicts with Homebrew Python on macOS #9966

@bebound

Description

@bebound

Description

In macOS 12 and 13, it has pre-installed Python /Library/Frameworks/Python.framework/Versions/3.xx/, which creates soft link such as /usr/local/bin/2to3-3.xx. Homebrew's python@3.xx also wants to create this link.

This causes issue when there is new Python is released, and brew install xx tries to install the latest Python: see Homebrew/homebrew-core#165793 (comment)

Runner image has a fix for Python 2.7:

choice_changes_xml=$(mktemp /tmp/python2_choice_changes.xml.XXXXXX)
sudo installer -showChoiceChangesXML -pkg $python2_pkg -target / | tee $choice_changes_xml > /dev/null
# To avoid symlink conflicts, remove tools installation in /usr/local/bin using installer choices
xmllint --shell $choice_changes_xml <<EOF
cd //array/dict[string[text()='org.python.Python.PythonUnixTools-2.7']]/integer
set 0
save
EOF

It used to let brew overwrite the python@3.11 soft link to resolve the conflict, but is removed in https://github.com/actions/runner-images/pull/8452/files#diff-5490845eec9cd46fa52e10c62bd6ec6a76c27f17a338963a508414efd8b2252dR33-R34

Now I have to run brew unlink python@3.11 && brew link --overwrite python@3.11 before using brew install xxx to eliminate the potential conflict. It's tedious.

There is a PR attempting to address this issue: #7710, but it was rejected. Regardless of whether the fix should be implemented in actions/setup-python, we are still facing this issue one year later. I believe the runner image should consider providing a temporary fix for this.

Related issue:
Homebrew/homebrew-core#173191
Azure/azure-cli#29054

Platforms affected

  • Azure DevOps
  • GitHub Actions - Standard Runners
  • GitHub Actions - Larger Runners

Runner images affected

  • Ubuntu 20.04
  • Ubuntu 22.04
  • Ubuntu 24.04
  • macOS 11
  • macOS 12
  • macOS 13
  • macOS 13 Arm64
  • macOS 14
  • macOS 14 Arm64
  • Windows Server 2019
  • Windows Server 2022

Image version and build link

This could be reproduced by reinstalling python@3.11

brew uninstall azure-cli
brew install python@3.11

https://github.com/bebound/starter-workflows/actions/runs/9298969591/job/25591905178

Is it regression?

Yes?

Expected behavior

Successfully install python@3.11 with brew.

Actual behavior

Pouring python@3.11--3.11.9.ventura.bottle.tar.gz
Error: The `brew link` step did not complete successfully
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/2to3-3.[11](https://github.com/bebound/starter-workflows/actions/runs/9298969591/job/25591905178#step:7:12)
Target /usr/local/bin/2to3-3.11
already exists. You may want to remove it:
  rm '/usr/local/bin/2to3-3.11'

To force the link and overwrite all conflicting files:
  brew link --overwrite python@3.11

To list all files that would be deleted:
  brew link --overwrite python@3.11 --dry-run

Possible conflicting files are:
/usr/local/bin/2to3-3.11 -> /Library/Frameworks/Python.framework/Versions/3.11/bin/2to3-3.11
/usr/local/bin/idle3.11 -> /Library/Frameworks/Python.framework/Versions/3.11/bin/idle3.11
/usr/local/bin/pydoc3.11 -> /Library/Frameworks/Python.framework/Versions/3.11/bin/pydoc3.11
/usr/local/bin/python3.11 -> /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11
/usr/local/bin/python3.11-config -> /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11-config

Repro steps

brew uninstall azure-cli
brew install python@3.11

Metadata

Metadata

Assignees

Labels

Area: PythonOS: macOSbug reportinvestigateCollect additional information, like space on disk, other tool incompatibilities etc.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions