Work with macOS

MacOS is based on the UNIX, and offers a command-line environment, which is very similar to Linux’ shell. On the other hand, occasional syntactical nuances can be irksome. Use man or refer to the A-Z index of Apple macOS for details.

In what follows, we list a few tips and tweaks for issues arising in our own use of macOS:


Enable x-forwarding when ssh to another computer

To enable x11 forwarding in the terminal on a Mac (that is, ssh to a remote Linux machine, and bring back windows to the local Mac computer), one needs to 

(1) install XQuartz: https://www.xquartz.org

(2) enable x11 forwarding by doing this:

sudo nano /etc/ssh/ssd_config

Toggle hidden files (mojave)

In a terminal, enter the following to show hidden files in Finder:

defaults write com.apple.finder AppleShowAllFiles -boolean true; killall Finder

Hide the hidden files with the following instruction:

defaults write com.apple.finder AppleShowAllFiles -boolean false; killall Finder

Uncomment the following line, and replace no with yes 

#X11Forwarding no

Python on macOS

Preliminaries

  • As of 2017, it is still better to use python 2.7.xx, because python3 is known to suffer from various compatibility problems.
  • Xcode and its Command Line Tools provide gcc compiler, as well as many linux-like functionalities. Xcode can be installed in Apps Store.
  • Homebrew is the Mac version of apt-get. To install, in the terminal, enter: 
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

When it has finished installing, enter 

brew --version 

to check it’s installed. The homepage of homebrew can be reached by entering: brew home

  • Pip is a program used to install python packages. It can be installed with the command: 
sudo easy_install pip 

Installing python 2

  1. Download the latest package for Mac OS X 10.6 and later from: https://www.python.org/downloads/release/python-2714/
  2. Alternatively, one can use the Anaconda package, downloadable from https://www.anaconda.com/download/#macos. Anaconda contains many python packages and the ipython command line environment. After installing anaconda, run the commands:
conda update conda
conda update ipython

To install TensorFlow with pip, enter

pip install -- upgrade tensorflow

Matplotlib number of blocks problem

When plotting with many dots, the python on MacOS may return an error that looks like

OverflowError: In draw_path: Exceeded cell block limit

To resolve the issue, enter the commands 

import matplotlib.pyplot as plt
plt.rcParams['agg.path.chunksize'] = 10000