Repository: Homebrew/homebrew-core

Issue #150306: [python-certifi] Error: The brew link step did not complete successfully
Created: 2023-10-09T17:03:13Z
brew gist-logs <formula> link OR brew config AND brew doctor output
$ brew config
HOMEBREW_VERSION: 4.1.15
ORIGIN: https://github.com/Homebrew/brew
HEAD: e57a87cfe9c15f192cd4fc6695a2b3b7acf0ddf7
Last commit: 5 hours ago
Core tap JSON: 09 Oct 16:38 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: ["--no-quarantine"]
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 15.0.0 build 1500
Git: 2.42.0 => /opt/homebrew/bin/git
Curl: 8.1.2 => /usr/bin/curl
macOS: 14.0-arm64
CLT: 15.0.0.0.1.1694021235
Xcode: N/A
Rosetta 2: false
$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  brew-pip
  exa

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  python-certifi
Verification

 My "brew doctor output" says Your system is ready to brew. and am still able to reproduce my issue.
 I ran brew update and am still able to reproduce my issue.
 I have resolved all warnings from brew doctor and that did not fix my problem.
 I searched for recent similar issues at https://github.com/Homebrew/homebrew-core/issues?q=is%3Aissue and found no duplicates.

What were you trying to do (and why)?
issue started here:
pypa/pipx#1080
What happened (include all command output)?
Upgrade brew.sh:
$ brew update && brew upgrade
==> Upgrading 2 outdated packages:
python-certifi 2023.7.22 -> 2023.7.22_1
python-mutagen 1.47.0 -> 1.47.0_1
==> Pouring python-certifi--2023.7.22_1.arm64_sonoma.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /opt/homebrew
Could not symlink lib/python3.10/site-packages/certifi/__init__.py
Target /opt/homebrew/lib/python3.10/site-packages/certifi/__init__.py
already exists. You may want to remove it:
  rm '/opt/homebrew/lib/python3.10/site-packages/certifi/__init__.py'

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

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

Possible conflicting files are:
/opt/homebrew/lib/python3.10/site-packages/certifi/__init__.py
/opt/homebrew/lib/python3.10/site-packages/certifi/__main__.py
/opt/homebrew/lib/python3.10/site-packages/certifi/cacert.pem
/opt/homebrew/lib/python3.10/site-packages/certifi/core.py
/opt/homebrew/lib/python3.10/site-packages/certifi/py.typed
==> Summary
🍺  /opt/homebrew/Cellar/python-certifi/2023.7.22_1: 43 files, 34.0KB
==> Running `brew cleanup python-certifi`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /opt/homebrew/Cellar/python-certifi/2023.7.22... (34 files, 27.7KB)
==> Pouring python-mutagen--1.47.0_1.arm64_sonoma.bottle.tar.gz
🍺  /opt/homebrew/Cellar/python-mutagen/1.47.0_1: 218 files, 1.8MB
==> Running `brew cleanup python-mutagen`...
Removing: /opt/homebrew/Cellar/python-mutagen/1.47.0... (218 files, 1.8MB)

What did you expect to happen?
work
Step-by-step reproduction instructions (by running brew commands)
run the commands

Duplicate issue #151232: Upgrading pyinvoke to 2.2.0_1 fails to link
Created: 2023-10-16T15:52:21Z
brew gist-logs <formula> link OR brew config AND brew doctor output
brew gist-logs pyinvoke
Error: No logs.

brew config
HOMEBREW_VERSION: 4.1.16
ORIGIN: https://github.com/Homebrew/brew
HEAD: c0c8a4dd4dd19ec16deb429abd50cdf82ea33b27
Last commit: 2 days ago
Core tap JSON: 16 Oct 15:46 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_EDITOR: nvim
HOMEBREW_MAKE_JOBS: 8
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 15.0.0 build 1500
Git: 2.42.0 => /opt/homebrew/bin/git
Curl: 8.1.2 => /usr/bin/curl
macOS: 13.5.2-arm64
CLT: 15.0.0.0.1.1694021235
Xcode: N/A
Rosetta 2: false

brew doctor
Your system is ready to brew.

Verification

 My "brew doctor output" says Your system is ready to brew. and am still able to reproduce my issue.
 I ran brew update and am still able to reproduce my issue.
 I have resolved all warnings from brew doctor and that did not fix my problem.
 I searched for recent similar issues at https://github.com/Homebrew/homebrew-core/issues?q=is%3Aissue and found no duplicates.

What were you trying to do (and why)?
Ran brew upgrade to bring everything up to date.
What happened (include all command output)?
Unfortunately I didn't notice the error until later, so I don't have the full output from the upgrade. But I have output from after:
❯ brew install pyinvoke
==> Downloading https://formulae.brew.sh/api/formula.jws.json
######################################################################################################################### 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
######################################################################################################################### 100.0%
Warning: pyinvoke 2.2.0_1 is already installed, it's just not linked.
To link this version, run:
  brew link pyinvoke
❯ brew link pyinvoke
Linking /opt/homebrew/Cellar/pyinvoke/2.2.0_1... 
Error: Could not symlink lib/python3.10/site-packages/invoke/__init__.py
Target /opt/homebrew/lib/python3.10/site-packages/invoke/__init__.py
already exists. You may want to remove it:
  rm '/opt/homebrew/lib/python3.10/site-packages/invoke/__init__.py'

To force the link and overwrite all conflicting files:
  brew link --overwrite pyinvoke

To list all files that would be deleted:
  brew link --overwrite --dry-run pyinvoke
❯ brew link --overwrite pyinvoke
Linking /opt/homebrew/Cellar/pyinvoke/2.2.0_1... 185 symlinks created.
What did you expect to happen?
pyinvoke to upgrade and remain linked.
Step-by-step reproduction instructions (by running brew commands)
brew upgrade pyinvoke

Closing comment (2023-10-19T17:56:10Z): Likely similar to #150306 where you installed something outside of brew using pip/pipx (or any other Python-specific package management tool) and that added a non-Homebrew copy of pyinvoke library.
Currently, you will need to follow output steps to handle this.
Homebrew has been adding more Python libs/formulae recently similar to other repositories/distros but we are probably not going to add everything needed to be PEP-668 (EXTERNALLY-MANAGED). So, users will end up experiencing issue mentioned in PEP https://peps.python.org/pep-0668/#abstract and will need to work around this.