Homebrew / homebrew-core

🍻 Default formulae for the missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
13.67k stars 12.37k forks source link

homebrew python version mis-reports #162000

Closed todd-dsm closed 8 months ago

todd-dsm commented 8 months ago

brew gist-logs <formula> link OR brew config AND brew doctor output

I've just installed Ansible on a new macOS/Sonoma; it installed Python as a dependency. 

When going after the info, I find `python@3.11`:

% brew info python 
==> python@3.11: stable 3.11.7 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/p/python@3.11.rb
License: Python-2.0
==> Dependencies
Build: pkg-config ✘
Required: mpdecimal ✔, openssl@3 ✔, sqlite ✔, xz ✔
==> Caveats
Python has been installed as
  /opt/homebrew/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /opt/homebrew/opt/python@3.11/libexec/bin

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /opt/homebrew/lib/python3.11/site-packages

tkinter is no longer included with this formula, but it is available separately:
  brew install python-tk@3.11

gdbm (`dbm.gnu`) is no longer included in this formula, but it is available separately:
  brew install python-gdbm@3.11
`dbm.ndbm` changed database backends in Homebrew Python 3.11.
...

However, when I go to find the install directory, it appears `python@3.12` is what's really installed on the system. 

```sh
% ls -d ${HOMEBREW_PREFIX}/opt/python@*
/opt/homebrew/opt/python@3.12

# This too
% pythonBin="$(brew --prefix python3)/libexec/bin"; echo $pythonBin
/opt/homebrew/opt/python@3.11/libexec/bin

### Verification

- [X] My "`brew doctor` output" says `Your system is ready to brew.` and am still able to reproduce my issue.
- [X] I ran `brew update` and am still able to reproduce my issue.
- [X] I have resolved all warnings from `brew doctor` and that did not fix my problem.
- [X] 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)?

I've configured too many laptops. The aim is to write a script that will automatically install some foundational tools like the GNU stuff, ansible, etc. The process I'd like to support would be something like:

Install, collect some info, then configure the system:

1. `brew install $package`
2. `pkgVersion="$(brew info $package --version)"` # EX: `3.12`
3. `pkgLoc="$(brew info $package --location)"`         # EX: `/opt/homebrew/opt/python@3.12`
4. `pkgLibs="$(brew info $package --libs)"` # EX: `/opt/homebrew/lib/python3.11/site-packages`

With this minimal info the script could verify some install details, like which directory was really installed? `python@3.11` or `python@3.12`.

Then, use `sed` to inject the paths into the `/etc/paths` file and move on. 

---

I'm not terribly particular in how I get this information though as long as its by some automatable method.

### What happened (include all command output)?

brew install ansible

### What did you expect to happen?

I expected ansible to install python as a dependency, then report the proper version when attempting to validate it.

### Step-by-step reproduction instructions (by running `brew` commands)

```shell
Uninstall

% brew uninstall --ignore-dependencies pycparser python-certifi python-cryptography python-dateutil python-jinja python-lxml python-markupsafe python-packaging python-pyparsing python-pytz python-setuptools python@3.12 ansible

Re-install 

```sh
brew install ansible
% brew install ansible 
==> Downloading https://ghcr.io/v2/homebrew/core/ansible/manifests/9.2.0
...
Already downloaded: /Users/user/Library/Caches/Homebrew/downloads/0c937877c3f0b283368d592efcf29df04420ed25940af4fba7768b3edb4a7dd1--python@3.12--3.12.1_1.arm64_sonoma.bottle.tar.gz
==> Fetching ansible
==> Downloading https://ghcr.io/v2/homebrew/core/ansible/blobs/sha256:6bc8ec29eac7898e887307061c73435ff5d97483d543e26baae476ce3389b027
Already downloaded: /Users/user/Library/Caches/Homebrew/downloads/5dbb1d63fdb9ba03b19d855b195783cc9c57a6a9cbd54ec2924d27e158c63ea8--ansible--9.2.0.arm64_sonoma.bottle.tar.gz
% brew --prefix python3
/opt/homebrew/opt/python@3.11

% brew info python     
==> python@3.11: stable 3.11.7 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/p/python@3.11.rb
License: Python-2.0
==> Dependencies
Build: pkg-config ✘
Required: mpdecimal ✔, openssl@3 ✔, sqlite ✔, xz ✔
==> Caveats
Python has been installed as
  /opt/homebrew/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /opt/homebrew/opt/python@3.11/libexec/bin

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /opt/homebrew/lib/python3.11/site-packages

tkinter is no longer included with this formula, but it is available separately:
  brew install python-tk@3.11
...

System Info

% brew config
HOMEBREW_VERSION: 4.2.7
ORIGIN: https://github.com/Homebrew/brew
HEAD: 6170b6297c61ef0b68814c708eeff2199d8b0d11
Last commit: 2 days ago
Core tap JSON: 07 Feb 01:11 UTC
Core cask tap JSON: 07 Feb 01:11 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 3.1.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: quad-core 64-bit dunno
Clang: 15.0.0 build 1500
Git: 2.43.0 => /opt/homebrew/bin/git
Curl: 8.4.0 => /usr/bin/curl
macOS: 14.2.1-arm64
CLT: 15.1.0.0.1.1700200546
Xcode: N/A
Rosetta 2: false
SMillerDev commented 8 months ago

brew install python will currently install 3.11 as you noticed. brew install python@3.12 will install 3.12.

It seems like your system is working correctly.

todd-dsm commented 8 months ago

in this case, there was a brew install ansible that brought a python dependency with it.

That dependency was installed as python@3.12. Afterwards, the brew info python command displays that python@3.11 is installed.

I'm not sure why this would be working as designed. Please advise.

SMillerDev commented 8 months ago

Because Ansible depends on Python 3.12 and the unversioned Python install that you checked is 3.11.

todd-dsm commented 7 months ago

Weird, I'd think homebrew would report on whatever was currently installed, as other package managers would; for example:

# dnf install neovim
Last metadata expiration check: 0:02:37 ago on Fri Feb 16 22:01:55 2024.
Dependencies resolved.
===================================================================================================================================================================================================
 Package                                            Architecture                            Version                                                  Repository                               Size
===================================================================================================================================================================================================
Installing:
 neovim                                             aarch64                                 0.9.5-1.fc39                                             updates    
...

Then, to check on that later:

# rpm -qa neovim
neovim-0.9.5-1.fc39.aarch64

Would be the general expectation.

Is there a method for asking homebrew ONLY about what's installed? (not what's available)

SMillerDev commented 7 months ago

brew ls will list what is installed. brew info python would also tell you if it was installed.