Louie Mac OS

Steps to fully setting up a new (or factory reset) Mac for Python data science and development. These steps are very opinionated and there are lots of other ways/tools to do this.

Homebrew

My current full time job is a cross platform position, with an emphasis on Macintosh support (Mac OS X Client and Server 10.5/10.6/10.7) and desktop engineering, this includes creating images. Jul 24, 2017 Whether you want to try out macOS, run Xcode or make a hackintosh you can use a virtual machine to get started on macOS. Remember the performance of macOS, particularly graphical support is very limited on a virtual machine so performance with graphical animations will be subpar compared to a real mac or hackintosh, but it will still get the job done.

  1. Install Homebrew
  2. Get the tree shell command: brew install tree

In order for Homebrew-installed tools to take precedence, include the following in your ~/.zshrc file (you might have to create it yourself). Utopia, an essay mac os. Apple recently switched from bash to zsh as its default shell which is nice.

A Note on .zshrc

More recent versions of Mac OS have switched over to using zsh as the default shell. If your version is older, it still uses bash as default. In that case, you can make edits to .bashrc or .bash_profile.

Running (System) Python

  • When you run python in Terminal, it will suggest using the python3 command instead
  • When you run python3 for the first time, it will request to install XCode CLT
    • This includes a copy of git, but it's probably out of date

Set up Git / Github

The git command is already enabled once you install XCode CLT, but we want to install an up-to-date version with Homebrew.

For example, on 2020-12-25, the copy of Git installed by XCode is git version 2.24.3 (Apple Git-128), but the current version on that date is actually 2.29.2.

Download the sims 4 complete. The default configuration for this new Git is just using the Keychain Password Manager.

We want to add our name and email globally (i.e. to every repo we work on). We also want to enable colored output.

Now the configuration is as seen below (or via ~/.gitconfig):

Now we just need to set up access to a specific Github account. First we generate a new SSH key:

Accept the default file location, and no passphrase.

If there isn't a file at ~/.ssh/config, create it, and modify the file as below:

Then:

Copy the key to your clipboard:

and paste into the Github New SSH Key section.

Python Setup

Install pyenv via Homebrew, for managing Python versions.

Add pyenv init to ~/.zshrc.

Safari for mac os x 10.4 11. Make sure you have the build dependencies (might be a little over-specified):

In Big Sur (OS 11.1) at the very least, installing new versions via pyenv is a little broken with Homebrew, etc. So put the following in ~/.zshrc:

You can then install other (non-system) versions of Python as shown below. This takes a little while since it is being built from source.

You can then change the version with pyenv global 3.8.6 or pyenv local 3.8.6.

Managing Python Environments

We will use Poetry for environment management. First install poetry:

Then enable poetry completions with:

and the following in ~/.zshrc (before compinit):

To create a new poetry project, use the following

Why Not conda?

Anaconda is a pretty popular distribution for Python (in data science). I used to use it exclusively, but stopped because:

  1. It's a little heavy for me (even miniconda)
  2. I prefer to rely on pypi offical packages rather than the Anaconda cloud
  3. It doesn't play nicely with Poetry -- or rather, Poetry doesn't play nicely with it
  4. I prefer having my Python versions separate from my project environments

Directory Structure

Set up a top-level directory in HOME called code. Dedicate a sub-directory per project/repo.

Fonts

We'll install Fira Code. To install on Mac, download the pack and Open the TTF files with FontBook. To enable on VSCode, paste the following in settings.json:

See the definitions of stylistic sets.

Louie Mac OS

Visual Studio Code

Install Visual Studio Code manually. You will need to add the code command to your PATH. Start Visual Studio Code, open the command palette, and choose Shell Command: Install ‘code’ command in PATH. You can then set VSCode as the default editor for CLI by putting the following in ~/.zshrc:

Louis Macouillard Prints

The settings file I use is here.

New Project

Explicit steps for creating a new code project.

Suggested starting values in the pyproject.toml file.

pytest plugins

Here's some pytest plugins I like to use:

  • pytest-randomly: Runs the tests in random order
  • pytest-cov: Integrates with coverage to see code coverage

Using iCloud

In case you like to use iCloud for documents rather than Google Drive/Dropbox/whatever. The path to the iCloud directory is ~/Library/Mobile Documents/com~apple~CloudDocs, so it's easier to just symlink it to something prettier.

Python Library Support

Through trial and error, here are some things you need to do to use some popular python libraries. Some of these manual installs are due to working on Mac OS 11.2 (Big Sur), but I'm honestly not sure which.

Louie Mac Os 11

Pillow

pillow is a dependency for a lot of popular visualization packages (e.g. matplotlib). It relies on some external libraries that you can install via homebrew. pillow documentation

Scipy

Louis macouillard prints

Useful in its own right. Also a dependency for numpy and matplotlib. It requires BLAS and LAPACK libraries. Docs here

Additionally, scipy relies on pymssql which needs

And finally when executing poetry add scipy, as per this issue comment, you should use:

Anaconda

In case we are using Anaconda or Miniconda..

After installing Miniconda and setting it up, we want to prioritize the Conda Forge channel. Following these instructions use the following commands:

Resources

  • This Dec 2020 guide for setting up a fresh Mac for software development
  • This May 2019 guide to setting up VSCode
  • 2020 Mac Setup: More general-purpose
IDNamePlatformArchitectureSingle-core ScoreMulti-core Score
7320995Dell Inc. XPS 13 7390Intel Core i7-10710U1596 MHz(6 cores)Windows 64x86_6410284614
6861787Samsung Galaxy Tab S7+ARM Qualcomm1804 MHz(8 cores)Android 64aarch649592986
6597093GenericAMD Ryzen 9 3900XT3793 MHz(12 cores)Windows 64x86_64133512607
6593692GenericAMD Ryzen 9 3900XT3793 MHz(12 cores)Windows 64x86_64129310648
6593644GenericAMD Ryzen 9 3900XT3793 MHz(12 cores)Windows 64x86_64129610688
6507289GenericIntel Core i5-104002892 MHz(6 cores)Windows 64x86_6411666089
6418904iPhone 12 ProApple A14 Bionic2990 MHz(6 cores)iOS 64aarch6415944066
6116381Mac mini (Late 2018)Intel Core i3-8100B3600 MHz(4 cores)macOS 64x86_648973396
5896023Mac mini (Late 2018)Intel Core i3-8100B3600 MHz(4 cores)macOS 64x86_648803249
3139404GenericAMD Ryzen 5 36003593 MHz(6 cores)Windows 64x86_6412747437
2702734HP HP ProDesk 600 G2 DMIntel Core i7-6700T2795 MHz(4 cores)Windows 64x86_649623580
2677078HP HP EliteDesk 800 G2 SFFIntel Core i7-67003391 MHz(4 cores)Windows 64x86_649853913
2677038HP HP EliteDesk 800 G2 SFFIntel Core i7-67003391 MHz(4 cores)Windows 64x86_6410043959
2592438GenericAMD Ryzen 7 3700X3593 MHz(8 cores)Windows 64x86_6412959180
2586962GenericAMD Ryzen 7 3800X3893 MHz(8 cores)Windows 64x86_6412969250
2483457GenericAMD Ryzen 7 3800X3893 MHz(8 cores)Windows 64x86_6413029250
2435337ASUS All SeriesIntel Core i7-4790K3999 MHz(4 cores)Windows 64x86_6411254226
2435180ASUS All SeriesIntel Core i7-4790K3999 MHz(4 cores)Windows 64x86_6411114226
2397047Google Pixel 3 XLQualcomm Qualcomm1766 MHz(8 cores)Android 64aarch645111906
2322772ASUS All SeriesIntel Core i7-4790K3999 MHz(4 cores)Windows 64x86_6411134279
2289331ASUS All SeriesIntel Core i7-4790K3999 MHz(4 cores)Windows 64x86_6411114212
2289218ASUS All SeriesIntel Core i7-4790K3997 MHz(4 cores)Windows 64x86_6410403398
2288735ASUS All SeriesIntel Core i7-4790K3999 MHz(4 cores)Windows 64x86_6411164138
2135674iPad8,9ARM2480 MHz(8 cores)iOS 64aarch6411124714
2135318iPad8,9ARM2480 MHz(8 cores)iOS 64aarch6411154648
2101058GenericAMD Ryzen 7 3800X3893 MHz(8 cores)Windows 64x86_6413049298
1937616GenericAMD Ryzen 7 3800X3893 MHz(8 cores)Windows 64x86_6412949184
1936449GenericAMD Ryzen 7 3800X3893 MHz(8 cores)Windows 64x86_6412889188
1864630GenericAMD Ryzen 7 3800X3893 MHz(8 cores)Windows 64x86_6412748461
1843332GenericAMD Ryzen 7 3800X3893 MHz(8 cores)Windows 64x86_6412788578
1171305Dell Inc. XPS 13 9380Intel Core i5-8265U1795 MHz(4 cores)Windows 64x86_6410293353
755561Microsoft Corporation Surface Laptop 3Intel Core i5-1035G71498 MHz(4 cores)Windows 64x86_6412294416
347726Microsoft Corporation Surface Pro 4Intel Core m3-6Y301496 MHz(2 cores)Windows 64x86_645691273
347701Essential PH-1Qualcomm Qualcomm1900 MHz(8 cores)Android 64aarch643841667
347688Microsoft Corporation Surface Pro 4Intel Core m3-6Y301496 MHz(2 cores)Windows 64x86_644501143
347643samsung SM-T830Qualcomm Qualcomm1900 MHz(8 cores)Android 64aarch643671254
347640iPhone 8 PlusApple A11 Bionic2390 MHz(6 cores)iOS 64aarch649352340
347634Google Pixel 3Qualcomm Qualcomm1766 MHz(8 cores)Android 64aarch645162102
347623MacBook Pro (15-inch Mid 2018)Intel Core i7-8850H2600 MHz(6 cores)macOS 64x86_6410775182
347598ASUS All SeriesIntel Core i7-4790K3997 MHz(4 cores)Windows 64x86_6410763707
347582ASUS All SeriesIntel Core i7-4790K3997 MHz(4 cores)Windows 64x86_649273718
292208Google PixelQualcomm ARMv81593 MHz(4 cores)Android 64aarch64319928
292205Essential PH-1Qualcomm Qualcomm1900 MHz(8 cores)Android 64aarch643891638
291996samsung SM-T830Qualcomm Qualcomm1900 MHz(8 cores)Android 64aarch643601399
291980Google Pixel 3Qualcomm Qualcomm1766 MHz(8 cores)Android 64aarch645121931
291974iPad mini 4Apple A81500 MHz(2 cores)iOS 64aarch64341670
291971iPhone 8 PlusApple A11 Bionic2390 MHz(6 cores)iOS 64aarch649262345
291958MacBook Pro (15-inch Mid 2018)Intel Core i7-8850H2600 MHz(6 cores)macOS 64x86_6410905192