Blog Posts

How to Easily Set Up Python on Any M1 Mac

Blog: Think Data Analytics Blog

After buying an M1 Mac, I realized how confusing is to properly set up Python with all data science packages (and non-data science packages) on the new Mac models.

According to this long Anaconda guide to the Apple Silicon, there are 3 options for running Python on the M1 — pyenv, anaconda, and miniforge.

In this guide, I will show you how to easily set up Python on any M1 Mac using anaconda and miniforge. Anaconda brings all the tools (including Python and Jupyter Notebook) and packages used in data science with one install, while miniforge gives you the freedom to set up the conda environment as you want, so you need to install any package on your own.

Note: The approaches mentioned in this guide won’t help you run Python natively on the M1 Macs but through Rosetta2. Python will work fine, just keep in mind that people see a 20–30% performance penalty when running x86–64 programs with Rosetta2 compared to native ARM64

Table of Contents
1. Setting up Python and Data Science Packages with Anaconda
 - Step 1: Download and Install Anaconda
 - Step 2: Launch Jupyter Notebook/Lab
 - Step 3: Install any additional library
2. Setting up Python with Miniforge
 - Step 1: Install Homebrew
 - Step 2: Install miniforge
 - Step 3: Setup and activate a virtual environment
 - Step 4: Install any Python library

Option 1: Setting up Python and Data Science Packages with Anaconda

The steps below will help you download the Anaconda installer with all the packages used for data science. With this option, we will be able to manage Anaconda using the graphical installer.

Step 1: Download and Install Anaconda

Go to Anaconda and click on the “Get started” button. A list will show up, choose the option “Download Anaconda installers.” Here you will see the Anaconda installers for all operating systems.

Download any 64-bit installer for macOS (both work fine with M1 models thanks to Rosetta2). In my case, I chose the “64-Bit Graphical Installer” to have that nice GUI Anaconda offers.

Once the file is downloaded, open it up to install Anaconda. A window will pop up, press “Continue” to start the installation.

Step 2: Launch Jupyter Notebook/Lab

Once Anaconda is installed, you’ll see a green circular icon that represents the Anaconda logo. Click on it to run anaconda. If you downloaded the graphical installer like me, you will see the Anaconda navigator shown below.

Image by author

The main applications for data science are Jupyter Notebook and Jupyter Lab. Let’s launch any of them and import a couple of data science libraries to check everything was set up correctly

import pandas as pd
import numpy as np

The first time you import the libraries it might take more than usual.

Step 3: Install any additional library

Anaconda brings the most common packages for data science, but there might be a couple of extra libraries you will need to install eventually.

To do so, go to the “Environments” section located on the left. Then choose the environment you’re using (the default it’s called “base”), click on the dropdown, and select “Not installed.” After this, all the packages available through the conda-forge channel will be displayed. On the search box, you can write any library you want and then check the box to install the library.

Image by author

That’s it! You’re ready to use Python for data science. If something is unclear, check the video below for more details.https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fn83J8cBytus%3Ffeature%3Doembed&display_name=YouTube&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dn83J8cBytus&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fn83J8cBytus%2Fhqdefault.jpg&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=youtube

Option 2: Setting up Python with Miniforge

Miniforge allows you to install the conda package manager. This option gives you the freedom to set up the conda environment as you want, so you need to install any package on your own.

Step 1: Install Homebrew

To easily install miniforge, first, we need to install Homebrew. Homebrew is an open-source package management system that simplifies the installation of software on macOS.

To install Homebrew, go to this website. There you will find the code below that you need to run in the terminal.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

The terminal will request your user’s password. Introduce it and then press return/enter to continue.

Note: To install Homebrew, you need to have XCode build tools installed. If you’re not sure whether you already have it, don’t worry; the terminal will let you know if XCode build tools is missing and ask to install it.

Step 2: Install miniforge

Once Homebrew is installed, restart the terminal and install miniforge running the following command.

brew install miniforge

In case you get the error zsh: command not found: brew, probably homebrew was saved in /opt/homebrew/ instead of /user/local/…
If that’s the case, you have to modify your PATH with the command below (more details on StackOverflow).

export PATH=/opt/homebrew/bin:$PATH

After this, you can use brew and install miniforge. Now it’s time to create and activate a virtual environment.

Step 3: Setup and activate a virtual environment

To install a virtual environment run the command below on the terminal. In this example, I’m going to create a new environment named test_env with Python 3.8

conda create --name test_env python=3.8

After this, you have to activate the environment running the following command.

conda activate test_env

Step 4: Install any Python library

Finally, you can install a Python package running the command below.

conda install PACKAGENAME

Let’s install the most popular Python libraries used in data science.

conda install numpy
conda install pandas
conda install matplotlib
conda install plotly
conda install scikit-learn

You should also install Jupyter Notebook and/or Jupyter Lab.

conda install jupyter
conda install jupyterlab

To run jupyter notebooks run the following command on the terminal.

jupyter notebook

That’s it! You’re ready to use Python for data science.

Original Source

The post How to Easily Set Up Python on Any M1 Mac appeared first on Big Data, Data Analytics, IOT, Software Testing, Blockchain, Data Lake – Submit Your Guest Post.

Leave a Comment

Get the BPI Web Feed

Using the HTML code below, you can display this Business Process Incubator page content with the current filter and sorting inside your web site for FREE.

Copy/Paste this code in your website html code:

<iframe src="https://www.businessprocessincubator.com/content/how-to-easily-set-up-python-on-any-m1-mac/?feed=html" frameborder="0" scrolling="auto" width="100%" height="700">

Customizing your BPI Web Feed

You can click on the Get the BPI Web Feed link on any of our page to create the best possible feed for your site. Here are a few tips to customize your BPI Web Feed.

Customizing the Content Filter
On any page, you can add filter criteria using the MORE FILTERS interface:

Customizing the Content Filter

Customizing the Content Sorting
Clicking on the sorting options will also change the way your BPI Web Feed will be ordered on your site:

Get the BPI Web Feed

Some integration examples

BPMN.org

XPDL.org

×