🌊

Python 2 を AArch64 の macOS (Apple silicon) で動かす

2025/02/14に公開

Python 2 を AArch64 (Apple silicon) の macOS で動かしたときのメモ。

  1. CPython の Git プロジェクトをレポジトリ (https://github.com/python/cpython) からクローンしてくる。
  2. Python 2 の一番新しいやつからブランチを作る。git checkout -b build-2.7.18 v2.7.18.
  3. 以下のように configure を書き換える。
$ git diff
diff --git a/configure b/configure
index 63d675312da..4d7aab7de8e 100755
--- a/configure
+++ b/configure
@@ -8474,6 +8474,9 @@ fi
        ppc)
                MACOSX_DEFAULT_ARCH="ppc64"
                ;;
+        arm64*)
+            MACOSX_DEFAULT_ARCH="arm64"
+            ;;
        *)
                as_fn_error $? "Unexpected output of 'arch' on OSX" "$LINENO" 5
                ;;
  1. ./configure して make する。
  2. python.exe が作成される。最適化や全てのモジュールなどが使えるようにするには、もうちょっといじらないといけないようだが、最低限の動作はする。
$ ./python.exe
Python 2.7.18 (tags/2.7-dirty:8d21aa21f2c, Feb 14 2025, 02:59:18)
[GCC Apple LLVM 16.0.0 (clang-1600.0.26.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'Hello!'
Hello!
>>> exit()

macOS Seqoia 15.3.1 で動作を確認した。

Discussion