We usually get this error when we do switching between networks.
Try this command and your error will be resolved:
$ sudo hostname -s 127.0.0.1
Another approach where you don't have to change the hostname of your Mac:
- Find the template file spark-env.sh.template on your machine (It is probably in /usr/local/Cellar/apache-spark/2.1.0/libexec/conf/).
- cp spark-env.sh.template spark-env.sh
- Add export SPARK_LOCAL_IP=127.0.0.1 under the comment for local IP.
Now, fire up the Spark-shell and it will work finely.
If you want to know more about Spark, then do check out this awesome video tutorial: