Homebrew, the package manager

I’ll do my best to answer, however 1) I don’t have access to my Mac right now, and 2) I don’t use Python, so you may have to validate what I say.

I assume you know that MacPorts requires Xcode’s command line tools, which are free from Apple. You don’t need the full-blown XCode development environment.

Q: Is installing Python on MacPorts as simple as running sudo port install python37 ?
A: Yes

Q: I take it that ports can be updated via sudo port upgrade outdated
A: Yes

Q: will this upgrade Python 3.7 to 3.8/further versions
A: I’m not sure, but I would guess not. However, if you ‘sudo install python3’ (instead of python37) I would guess that it would upgrade in the manner you describe.

Q: How do I ensure that packages/scripts that need Python 3 have access to it without making changes to the macOS Python
A: When you install a “port” (a package), the port will specify what it needs and MacPorts will install it automatically. MacPorts installs everything in a dedicated directory structure, and it will install everything except software that is included in the XCode command line tools. Python is not part of XCode so MacPorts will install it (if needed). Presently, that means you would have multiple installations of Python (the one Apple includes, and the one you install with MacPorts). The ports are built to use MacPort’s installation of Python.

Q: Does using Miniconda/Anaconda fit into this (specifically point 3?) It looks like Anaconda would need me to install packages from Conda and so it replaces MacPorts instead of working with it. Would this be correct?
A: From a cursory glance at their website it appears you are correct. I don’t know how installing multiple package managers would work out but it doesn’t seem like a good idea to me.

Edit: Thanks for the link @Ajay, it explains the differences between MacPorts and Homebrew very well.

1 Like

I also prefer MacPorts. Since I like to use the terminal a lot, having tons of amaziong packages just an “install” away, is great.

1 Like

Well, I had a nice long answer typed up and lost it somehow.

Anywho, your life will be much happier, including fluffy kittens and green meadows, if you install Anaconda and use conda. Conda manages packages for your Python install, and creates and manages environments. These environments can be set up with different versions of python, packages, etc. You can further switch between them, thus having them set up for different projects. It does this by changing the environment variables, paths, symlinks, etc.
With Anaconda, you also get Anaconda Navigator which can manage packages, environments, and applications like PyCharm, which is a nice IDE for python development.

I recommend you install iTerm2, which can change the prompt to reflect the conda environment (as well as git branches, etc.).

1 Like

So you use Anaconda and Homebrew?

BTW, I’m glad you chimed in here because, as I said, I don’t use Python, and I know you do.

Yes, they serve different purposes.
I use conda for python-specific things, and homebrew for non-python.

Lol. I was careful to give you first crack at it.

1 Like

@Ajay might be interested in these free Python books.

1 Like

I originally used MacPorts for package management on MacOS, but switched to Homebrew for two reasons (many years ago):

  1. The bloat caused by not re-using dependencies / not using built-in libs by MacPorts was extensive. I remember it being many GB of wasted space on my first Macbook, which only had a 128GB HD so the space was precious.
  2. Homebrew packages were updated far, far more frequently. MacPorts had many more packages available, but many of them were out of date. When it came to packages I actually wanted to install, Homebrew invariably had the most current version, whereas MacPorts often did not.

Admittedly, I made the switch to brew many years ago and haven’t revisited this decision since then, but that was my reasoning back then.

Something else I like about Homebrew is the brew cask command, which allows you to very easily install GUI applications from the command line as well. I just bought a new MBP, and setup of my fairly involved system was pretty easy with Homebrew. All the dev type stuff I installed with normal brew, and the vast majority of my favorite GUI apps are available as casks, as simple as brew cask install chrome. I just have a list of the casks I want to install that I feed to the command, and boom, I’m setup with my GUI apps.

2 Likes

Homebrew supports multiple versions, and even supports multiple versions being installed, and switching between them. Homebrew install specific version of formula? - Stack Overflow

Homebrew also has the brew doctor command for checking out the installed packages and system for possible problems.

My experience with Fink and MacPorts was similar to @acnebs, and in addition to the bloat, at some point they both just made a mess of things. Admittedly that was several years ago. After installing homebrew, that hasn’t happened, and it’s worked really well for me.

1 Like

Thank you all very much for your thoughtful and detailed responses.

@jec0047, looking back I think I should have framed point 3 better! It looks like packages installed with MacPorts will access the MacPorts installed version of Python without any trouble. However, I do use some simple scripts that call on Python and it is these that broke for a while when Python 2 reached EOL. Do I need to/would you guys recommend doing something like sudo port select --set python python35 and/or sudo port select --set python3 python35 to make sure that scripts have access to the MacPorts Python or would this qualify as tinkering with the macOS Python and hence not be advisable?

@JohnAtl, thanks for recommending the books and for your recommendations. I confess that much of it is beyond me at the moment! I am able to run the few, basic scripts and packages that I use (qpdf, youtube-dl etc.) and my needs aren’t greater than that at the moment and so, from a cursory look a few days ago, I felt that Anaconda might be an overkill. I must check out those books to learn more!

1 Like

Your second point first: This makes perfect sense and I would have done the same thing with the small HDD.

As to the first point, a lot of those built-in libs (and whole applications) are going to be disappearing at some point, when Apple stops distributing them with macOS.

Yes, I think you would want to do ‘sudo port select…’. No, that will not tinker with the built-in versions. Note, however, that if the scripts you are using name a specific binary (e.g. ‘/usr/bin/python …’), which is quite likely, then that binary will be used. To correct that, you will have to modify the scripts.

1 Like

Right, so the scripts I am looking at call /usr/bin/env python :thinking: What would I have to do in this case?

These scripts are downloaded from GitHub and apparently I am not supposed to change anything inside or else they don’t auto-update if I understand correctly :grimacing:

Is there anything else that I should do? I think I did run ln -sf /usr/bin/python2.7 /usr/bin/python when I had done the initial setup. Apologies if I am asking very basic questions!

After installing MacPorts and doing the ‘sudo port select …’, ‘/usr/bin/env python’ should give you the right binary. What you need to look out for are references to /usr/bin/python.

Thank you! I am looking forward to giving MacPorts a go.

EDIT: Would you recommend doing this to use the latest version of Git?

Without knowing your use case it’s kinda hard to make a recommendation. Personally, I don’t use git yet, although I’m getting to the point where I’ll soon need to. If I were using git, and I was using it only for personal work, and only with xCode, I’d probably just use the Apple version unless that version was buggy or lacked some necessary feature. Otherwise, yes, I would install git via MacPorts.

I don’t know if it would be difficult to make xCode use that version, or even if you would want to. One faq about MacPorts is “Will my ports survive a major macOS upgrade?” and I believe the short answer is “No” (the same is true of Homebrew). This would mean, for example, that if you were using the MacPorts version with xCode and you upgraded to macOS 10.16 in the future, all of your xCode projects would be unavailable until you brought your ports up to speed.

1 Like

Homebrew handles upgrades to macOS really well, and it sounds like better than MacPorts. I don’t recall ever having a problem.

From the linked post:

  1. Run the macOS installer: startosinstall
  2. Run all macOS updates for Xcode, etc…: softwareupdate -ai
  3. Update homebrew itself and the package “lists”: brew update
  4. Upgrade all the software homebrew installed: brew upgrade
  5. Update any software installed with cask: brew cask upgrade

I don’t know how macports in keeping list of packages versions etc, but using homebrew one can install old versions. I had an issue where I see to install python 2 which is currently not avaiable on homebrew as it get deprecated but searching and going back in history in git make it work.

I’ve been wondering what casks were - thanks!

Also thank you for the brew-bundle link - didn’t even know that existed! Doubt I’d use it regularly, but nice to have for fast installs in case of drive replacement, nuke-and-pave, etc.

1 Like

While I’m not afraid of the terminal, Cakebrew is awesome! Thanks for that

1 Like