# sci-pi.org.uk on MacOS

Whilst MacOS provides a copy of python, pre-Catalina it was only python 2, with only the core packages, and no easy way to add to them. So here we suggest installing python 3 from https://www.python.org/, which will require around 150MB of disk space (and a little more during the installation).

MacOS Catalina and Big Sur do provide some form of python3. Whether
they have a working version of pip3, and thus allow one to skip
straight to the `pip3`

commands below, I cannot tell, as
my Mac hardware is too old to run Catalina...

Python 3 for MacOS can be downloaded from https://www.python.org/ - hover on Downloads, and press the MacOS X download button. When it finishes, click on "Install Certificates" as instructed.

To see if this step was successful, open a Terminal window (found in the Utilities subfolder of Applications, not in Applications itself), and type:

python3 --version

The response should be 3.8.2 (or later).

Three python packages are much used on this site, and not installed by default. It is probably best to add them now, by typing in the Terminal window:

pip3 install --user numpy pip3 install --user matplotlib pip3 install --user numba

Then one should test the above, again in the Terminal window (with the end of the prompt now shown):

~$ mkdir maths ~$ cd maths ~/maths$ curl -O http://www.sci-pi.org.uk/maths/mandel_v2.py ~/maths$ python3 mandel_v2.py

This should display the Mandelbrot Set example. Similarly

~/maths$ curl -O http://www.sci-pi.org.uk/maths/mersenne_fast.py ~/maths$ python3 mersenne_fast.py

should find all Mersenne primes
up to M_{3300}.

Want more Mersenne primes? One can open the python code as a text file with

~/maths$ open -a TextEdit mersenne_fast.py

and change the 3300 to 4424. Press Apple S to save the file, and then type

~/maths$ time python3 mersenne_fast.py

That would take a Pi 4 running 32 bit Raspbrian 54 seconds. It took a late 2011 MacBook Pro (64 bit) 13.3 seconds (or 19.6 seconds with the Turbo Boost off).

If you have reached this point successfully, you should also be able to run most of the examples on this website.

## numba

Currently (end March 2021) the above all works fine. There was a period during which numba would fail to install using this recipe. Apart from avoiding the examples on this site which use numba, one could also get around the issue by using an older version of python.

At that time, the answer was to use the 3.8 series, so
one simply had to go to the
complete list of MacOS
python downloads and install the most recent of the 3.8 series
(currently 3.8.7). Then everywhere you would type `python3`

or `pip3`

type `python3.8`

or
`pip3.8`

. So you should be able to run

pip3.8 install --user numpy pip3.8 install --user matplotlib pip3.8 install --user numba curl -O http://www.sci-pi.org.uk/maths/mandel_tk.py python3.8 ./mandel_tk.py

I retain this information in case python 3.10 is launched with no corresponding compatible numba package, and this will then show how one can revert to 3.9. Or similarly for any other future version.

## A C compiler

One might also wish to install a C compiler for a couple of the examples on this website. To install that provided by Apple, but not installed by default, simply type in a Terminal window:

gcc --version

If `gcc`

is not already installed, MacOS will ask
whether you wish to install the "command line developer tools." It
will take another 150MB or so.