Choices for building a Python development environment on M1 Mac (Apple Silicon)

I longed for Apple silicon and bought an M1 Macbook Air, but this was quite a songwriter.As a programming study / development environment, windows or Intel mac may be better.I'm not familiar with other programming languages ​​so I don't know,Here is a summary of possible options for M1 Mac as a development environment for Pyhon and how to build it.

Python development environment choices on M1 mac

A quick survey shows that the following three are the current (September 2021) main options.

  • Install with Homebrew
  • Use Anaconda environment (miniforge)
  • Use Docker

The reason why the environment construction on M1 Mac is complicated is that Apple silicon uses the Arm architecture as the CPU architecture (instruction system design) unlike the conventional intel x86 series.If you read the article below about this, you can get an idea of ​​it.

IT engineer's tips What is the CPU architecture?
What makes a mac with an ARM M1 processor different from the Intel version?

Install python directly with Homebrew

How to install python using the package manager "Homebrew" for macOS (or Linux).

·merit

Easy to install as it is the de facto standard tool in the MacOS environment

-Demerit

Some Python packages are compatible with the M1 Arm architecture, and some only work on Rosetta, so you need to check each time you install the package, so be careful when using it.

I haven't done it, but the following is more concise.

Rosetta 2 is an emulation software that allows traditional Intel Mac binaries to work on Arm-based M1 Macs.

The Apple M2's Fast Secrets Found by Examining Rosetta 1

Use Anaconda environment (miniforge)

Anaconda Is a platform that provides an environment for data science.We provide compiled binary files of many modules and tools centered on scientific calculations, and you can easily build an environment that uses Python.

Miniconda on m1 mac (Minicon version of Anaconda: Reference Comparison of Anaconda and Miniconda) ForkminiforgeIs used.

·merit

Easy environment construction and virtual environment management. arm native and fast.
You don't have to worry about M1 support for python packages.

-Demerit

If you use pypi (pip) to insert a package that is not in the conda repository (cannot be installed with miniforge), the environment may be destroyed by an unexpected conflict and you may need to reinstall it (reference: conda and pip: Danger of mixing

The following article (+ video) was very helpful for this.

What is miniforge ...

Miniconda with a focus on supporting various CPU architectures (intel x86_64 and ppc64le, aarch1 including Apple M64).

Use Docker

How to create a python environment on a Docker container.

·merit

If you create a container for each environment, you will not have to worry about collisions.
You don't have to worry about M1 support for python packages.

-Demerit

Docker learning costs.Depending on the process, it is slower than the two above.

The method is summarized here.

Summary

In reality, "Use Anaconda environment (miniforge) "or"I think it will be "use Docker".Try it with miniforge first, and if you find any inconvenience, start using Docker.Please let me know if there is another better way.

If you just want to execute the codeGoogle CollaboratoryThere are some, but I omitted it because it cannot be said to be an environment construction.