Installing Flutter for iOS and Android on M1 Macbook

What is Flutter?

Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase.

Installing Flutter’s SDK

  • Downloaded the Flutter SDK (version 1.22.5) to the desired location and extract the file. As an example if the file is downloaded to ~/Documents/develop/flutter_install, run:
cd ~/Documents/develop/flutter_install
unzip ~/Documents/develop/flutter_install/
  • Update your path. For ZSH, update ~.zshrc
nano ~/.zshrc

export PATH="$PATH:$HOME/Documents/develop/flutter_install/flutter/bin"
  • To refresh the current window, run:
source ~/.zshrc 

or open a new terminal window to automatically source the file.

  • Verify that the flutter/bin directory is now in your PATH by running:
echo $PATH
  • Verify that the flutter and dart commands are available by running:
which flutter dart

Link to the Flutter document

Installing Xcode and the iOS SDK

To develop Flutter apps for iOS, you need a Mac with Xcode installed.

  • Install Xcode from the Apple App store
  • To prepare to run and test your Flutter app on the iOS simulator, run
open -a Simulator

Installing Android Studio

Flutter relies on a full installation of Android Studio to supply its Android platform dependencies.

  • Download and install Android Studio.
  • Start Android Studio, and go through the ‘Android Studio Setup Wizard’. This installs the latest Android SDK, Android SDK Command-line Tools, and Android SDK Build-Tools.
  • Install the Flutter plugin for Android Studio
    • Open plugin preferences (Configure > Plugins)
  • Select the Fultter plugin and click Install
  • The Flutter plugin requires the Dart plugin to be installed, click Install
  • Restart Android Studio when prompted
  • Run the following command and press y to accept every license.
flutter doctor --android-licenses

Create a Flutter app from template

  • Create an empty directory for your Flutter apps. As an example
mkdir ~/Documents/develop/flutter
cd ~/Documents/develop/flutter
  • Use the flutter create command to create a new project:
flutter create calc
cd calc
  • Ensure that the iOS simulator is up and running
open -a Simulator
  • Run the app with the following command:
flutter run

Running the code on M1 Macbook Pro

If you encounter the following error message:

[] Error retrieving thread information: (ipc/send) invalid destination port

Switch to the beta branch, released at the beginning of the month, usually the first Monday. This will include a branch for Dart, the Engine and the Framework.

flutter channel beta
flutter upgrade
flutter clean
flutter run

If everything works well, there will be no error messages

Happy Fluttering!

How to run PySpark 2.4.0 in Jupyter Notebook on Mac

Install Jupyter notebook

$ pip3 install jupyter

Install PySpark

Make sure you have Java 8 or higher installed on your computer and visit the Spark download page

Select the latest Spark release, a prebuilt package for Hadoop, and download it directly.

Unzip it and move it to your /opt folder:

$ tar -xzf spark-2.4.0-bin-hadoop2.7.tgz
$ sudo mv spark-2.4.0-bin-hadoop2.7 /opt/spark-2.4.0

A symbolic link is like a shortcut from one file to another. The contents of a symbolic link are the address of the actual file or folder that is being linked to.

Create a symbolic link (this will let you have multiple spark versions):

$ sudo ln -s /opt/spark-2.4.0 /opt/spark̀

Check that the link was indeed created

$ ls -l /opt/spark̀

lrwxr-xr-x 1 root wheel 16 Dec 26 15:08 /opt/spark̀ -> /opt/spark-2.4.0

Finally, tell your bash where to find Spark. To find what shell you are using, type:

$ echo $SHELL

To do so, edit your bash file:

$ nano ~/.bash_profile

configure your $PATH variables by adding the following lines to your ~/.bash_profile file:

export SPARK_HOME=/opt/spark
# For python 3, You have to add the line below or you will get an error
export PYSPARK_PYTHON=python3

Now to run PySpark in Jupyter you’ll need to update the PySpark driver environment variables. Just add these lines to your ~/.bash_profile file:


Your ~/.bash_profile file may look like this:

Restart (our just source) your terminal and launch PySpark:

$ pyspark

This command should start a Jupyter Notebook in your web browser. Create a new notebook by clicking on ‘New’ > ‘Notebooks Python [default]’.

Running PySpark in Jupyter Notebook

The PySpark context can be

sc = SparkContext.getOrCreate()

To check if your notebook is initialized with SparkContext, you could try the following codes in your notebook:

sc = SparkContext.getOrCreate()
import numpy as np
TOTAL = 10000
dots = sc.parallelize([2.0 * np.random.random(2) - 1.0 for i in range(TOTAL)]).cache()
print("Number of random points:", dots.count())
stats = dots.stats()
print('Mean:', stats.mean())
print('stdev:', stats.stdev())

The result:

Running PySpark in your favorite IDE

Sometimes you need a full IDE to create more complex code, and PySpark isn’t on sys.path by default, but that doesn’t mean it can’t be used as a regular library. You can address this by adding PySpark to sys.path at runtime. The package findspark does that for you.

To install findspark just type:

$ pip3 install findspark

And then on your IDE (I use Eclipse and Pydev) to initialize PySpark, just call:

import findspark
import pyspark
sc = pyspark.SparkContext(appName="myAppName")

Here is a full example of a standalone application to test PySpark locally 

import findspark
import random
from pyspark import SparkContext
sc = SparkContext(appName="EstimatePi")
def inside(p):
x, y = random.random(), random.random()
return x<em>x + y</em>y &lt; 1
NUM_SAMPLES = 1000000
count = sc.parallelize(range(0, NUM_SAMPLES)) \
print("Pi is roughly %f" % (4.0 * count / NUM_SAMPLES))

The result:


Based on this article and on this article