HomeBrew and Python installation on Mac Book PRO

Dear Mac Experts,


I would appreciate getting some help installing HomeBrew and Python on my laptop.

I have a Mac Boo Pro 16" running macOS BigSur version 11.4


I have enrolled in an online school that will teach techniques to reconstruct images from CT, PET, MRI raw data. Such techniques are available in a development framework and make use of a biomedical library (SIRF and CIL)

Both SIRF and CIL are available for Mac, Linux, and will be available for Windows as well.


To work out the online examples, Mac attendees are required to install XCode, HomeBrew, and Python.


I already have XCode installed on my Mac. However, there is no HomeBrew.


I believe this Mac comes with Python 2.7 installed. In a terminal window I did the following:


mauramonville@Mauras-MacBook-Pro site-packages % pwd

/Library/Python/2.7/site-packages

mauramonville@Mauras-MacBook-Pro site-packages % ls

Extras.pth README

mauramonville@Mauras-MacBook-Pro site-packages % cat README 

"This directory exists so that 3rd party packages can be installed here.  Read the source for site.py

for more details."


Python seems to be installed as the command "python" responds when I enter it on the terminal window. However, the school will require the latest Python version that is higher than 2.7.


The school has published the installation instructions on the following website:

https://github.com/SyneRBI/SIRF/wiki/SIRF-SuperBuild-on-MacOS#Install_XCode_and_Homebrew

but they are quite confusing to me. In fact, XCode is already installed on my Mac. I still need HomeBrew and the latest Python.

There are instructions about integrating SIRF and CIL with MathLab, which I would like to use. Unfortunately, school instructors will demonstrate SIRF and CIL usage with Python.


My concern is to screw up my currently working Mac configuration.

Your help is more than welcome.


Thank you in advance.

Kind regards,

Maura E. M.

MacBook Pro 16″, macOS 11.4

Posted on Jun 27, 2021 2:29 AM

Reply
Question marked as Top-ranking reply

Posted on Jun 27, 2021 7:19 AM

Because you are installing third-party Python libraries, you do not want to install these with the Apple-provided Python versions. Even if your school's instructions suggest that this is okay, don't do it. I use the plural here because, in addition to Python 2.7.16, Xcode also installs a 3.8.2 version in /usr/bin/python3. Leave these alone.


It is important that you know in advance what versions of Python that those school recommended Python libraries support because if they want Python 3.8 (example), they will likely break with a newer version. The link in the next paragraph gets you to recent versions of Python3 for the Mac.


What I have personally done is visit Python.org and download their Mac-friendly Python 3.9.5 installer. It installs its library in /Library/Frameworks and then soft links from its library, the binaries back into /usr/local/bin. Simple as pie, and nothing Apple-related gets stepped on.


Once you have the preceding paragraph accomplished, you should adjust your PATH in your ~/.zshrc, or ~/.bash_profile shell dotfiles:


export PATH=".:/usr/local/bin:${PATH}"


Homebrew, on Intel Big Sur, still uses the /usr/local tree for its package installation, and /opt/homebrew tree on M1 Macs. If from above, you already have installed some version from Python.org, although any brew package dependencies that require it to install (currently) Python 3.9.5, it will build them, but not attempt to move those Python binaries from /usr/local/homebrew into /usr/local/bin. No big deal.


When I intend to install third-party Python libraries, I create a Python virtual environment to isolate that content from the original Python library by stuffing it all in an arbitrarily named folder, the following example is in my home directory:


/usr/local/bin/python3 -m venv ~/py39venv
source ~/py39venv/bin/activate && cd ~/py39venv
# install your libraries in this venv
# and when done
deactivate && cd -


Once I have changed the directory to ~/py39venv, I am free to install third-party libraries in that folder, and under no risk of screwing up my Mac.


On your Intel Mac, homebrew expects that /usr/local exists before you install homebrew. Once brew is installed, you can

brew update
brew upgrade
brew cleanup


It is a good idea to see what your package dependency tree looks like for an uninstalled package before you pull the trigger:


brew deps --tree --installed package_name
# get information on it
brew info package_name
# then you can install it
brew install package_name
# list your installed packages
brew list
# and then cleanup again
brew cleanup



Similar questions

7 replies
Question marked as Top-ranking reply

Jun 27, 2021 7:19 AM in response to mauede33

Because you are installing third-party Python libraries, you do not want to install these with the Apple-provided Python versions. Even if your school's instructions suggest that this is okay, don't do it. I use the plural here because, in addition to Python 2.7.16, Xcode also installs a 3.8.2 version in /usr/bin/python3. Leave these alone.


It is important that you know in advance what versions of Python that those school recommended Python libraries support because if they want Python 3.8 (example), they will likely break with a newer version. The link in the next paragraph gets you to recent versions of Python3 for the Mac.


What I have personally done is visit Python.org and download their Mac-friendly Python 3.9.5 installer. It installs its library in /Library/Frameworks and then soft links from its library, the binaries back into /usr/local/bin. Simple as pie, and nothing Apple-related gets stepped on.


Once you have the preceding paragraph accomplished, you should adjust your PATH in your ~/.zshrc, or ~/.bash_profile shell dotfiles:


export PATH=".:/usr/local/bin:${PATH}"


Homebrew, on Intel Big Sur, still uses the /usr/local tree for its package installation, and /opt/homebrew tree on M1 Macs. If from above, you already have installed some version from Python.org, although any brew package dependencies that require it to install (currently) Python 3.9.5, it will build them, but not attempt to move those Python binaries from /usr/local/homebrew into /usr/local/bin. No big deal.


When I intend to install third-party Python libraries, I create a Python virtual environment to isolate that content from the original Python library by stuffing it all in an arbitrarily named folder, the following example is in my home directory:


/usr/local/bin/python3 -m venv ~/py39venv
source ~/py39venv/bin/activate && cd ~/py39venv
# install your libraries in this venv
# and when done
deactivate && cd -


Once I have changed the directory to ~/py39venv, I am free to install third-party libraries in that folder, and under no risk of screwing up my Mac.


On your Intel Mac, homebrew expects that /usr/local exists before you install homebrew. Once brew is installed, you can

brew update
brew upgrade
brew cleanup


It is a good idea to see what your package dependency tree looks like for an uninstalled package before you pull the trigger:


brew deps --tree --installed package_name
# get information on it
brew info package_name
# then you can install it
brew install package_name
# list your installed packages
brew list
# and then cleanup again
brew cleanup



Jun 27, 2021 5:44 PM in response to mauede33

mauede33 wrote:

The school has published the installation instructions on the following website:
https://github.com/SyneRBI/SIRF/wiki/SIRF-SuperBuild-on-MacOS#Install_XCode_and_Homebrew
but they are quite confusing to me.

They are also years out of date - and, by their own admission, untested.

In fact, XCode is already installed on my Mac. I still need HomeBrew and the latest Python.

Just so you know, HomeBrew is for people too lazy to properly build software. Then they dump people like you on these forums so that we can sort out their mess for them.

There are instructions about integrating SIRF and CIL with MathLab, which I would like to use. Unfortunately, school instructors will demonstrate SIRF and CIL usage with Python.

My concern is to screw up my currently working Mac configuration.

That is a valid concern.


My recommendation would be to download Parallels Desktop from the Mac App Store: https://apps.apple.com/us/app/parallels-desktop/id1085114709?mt=12


Do NOT be tempted or swayed by marketing to install the other version of Parallels Desktop that isn't in the Mac App Store. You don't want that one. You want the one in the Mac App Store. It will cost $100/year, but it will be well worth it.


Then, install the free Ubuntu Linux operating system in Parallels. This is one of the built-in options and very easy to do. Then, you can follow these instructions: https://github.com/SyneRBI/SIRF/wiki/SIRF-SuperBuild-Ubuntu


If you do this, you don't have to worry about Python 2.7 vs Python 3.x. You don't have to worry about HomeBrew. You don't have to worry about permission on /usr/local. You don't have to worry about any of the other random things are are likely to fail during the Mac install process.

Jun 28, 2021 7:22 AM in response to mauede33

If your only goal is to install Python3, and the other libraries that the school recommends can be installed by Python3's own package installer (pip), or a means other than homebrew, then you really don't need homebrew at all. Keep it simple. Use the appropriate Python3 installer from Python.org, and the keep your Python development environment contained within a designated venv folder.


Or follow etresoft's advice.

Jun 28, 2021 1:30 AM in response to VikingOSX

Thank you so much.

I used to fiddle about with bash when I was running Linux. I never messed up with bash on Mac.

I got spoiled by using exclusively high-level languages. Primarily MatLab.


If I understood your suggestions correctly, you recommend I avoid following the school guidelines for the installation of the scripting language and the development environment.

I am still confused about the installation order. You suggested installing Python first from its original website and then HomeBrew.

However, HomeBrew will install Python as well. Am I right/wrong?

To avoid possible incompatibilities of duplicated libraries you encapsulate your Python installation in a separate folder.

If I install Python first then why shall I still install HomeBrew?

My understanding /misunderstanding is that HomeBrew is a Python installer for Mac.

Can you please explain?

Thank you




Jun 28, 2021 2:17 AM in response to etresoft

Thank you.

I had bought Parallel Desktops with my first Mac Book Pro (17"). I thought I would need to run Windows but then

I never installed it.

Parallel Desktops is like a virtual machine.

The image reconstruction library that is the object of the school will benefit from the availability of GPUs and/or multi-core platform.

Will whatever runs in the virtual machine have access to all the cores installed on the Mac? Will it have access to multi-threading?

SIRF and CIL are a framework for image reconstruction from CT, PET MRI scans. I suspect they use iterative algorithms that are number-cruncher processes. I am concerned about the speed.

Thank you


Jun 28, 2021 4:12 AM in response to mauede33

mauede33 wrote:

Parallel Desktops is like a virtual machine.

It is not like a virtual machine, it is a virtual machine.

The image reconstruction library that is the object of the school will benefit from the availability of GPUs and/or multi-core platform.
Will whatever runs in the virtual machine have access to all the cores installed on the Mac? Will it have access to multi-threading?

You can configure it to have access to all the cores. GPUs are always challenging with a VM.

SIRF and CIL are a framework for image reconstruction from CT, PET MRI scans. I suspect they use iterative algorithms that are number-cruncher processes. I am concerned about the speed.

Don’t be concerned about speed. You won’t have much of that.


My recommendation is based on getting you up to speed with an environment that you can use to follow along in class. It will be grossly unsuitable for any real work. You are welcome to try to get it running natively in your Mac instead. You might want to put the medical classes on hiatus for a few years while you get that computer science degree. You will also need a few years learning how to build and install poorly-written open-source software on a Mac. Or you can take a chance with Homebrew. Who knows? It might work.


However, even if you get it running on your Mac, all you would get from that is slightly higher performance while running the demo data sets for school. If you want to do any real work or make use of this experience to get a job, you will have to go back to square one and get it all working on Linux. I’m suggesting you cut out the middle-msn and just learn to do it on Linux. Then, when you want to do a bigger project, you could run it on much more powerful machines on AWS. Telling a potential employer that you got it running on your Mac with Homebrew isn’t going to impress anyone. Telling them you got it working on AWS will get you a much different reaction.

Jun 28, 2021 1:48 PM in response to VikingOSX

Thank you to you all.

The SIRF-CIL school started today. They posted a video with the instructions to download Docker and then clone a lot of code from a repository on GitHub.

Unluckily the named repository is not in GitHub at the given address.

Once I succeed in cloning the SuperBuild repository then Python will be available in the Docker environment (I was told).

We are also given access to cloud machines with different configurations and computing power. All the cloud machines have the SIRF-CIL code and image data. Unluckily no one has managed to start his/her cloud machine so far. A spate of errors printed on the screen at each attempt to start the cloud machine.

Many participants have reported such setbacks. Hopefully, the school organizers will address them ASAP.

I expect to come across other hurdles. Expect me to bother you again... sorry.

Thank you





This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

HomeBrew and Python installation on Mac Book PRO

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.